import { DataTypes, Model, Optional } from 'sequelize';
import { sequelize } from '@config/database';

export interface Form16SapResponseAttributes {
  id: number;
  trnsUniqNo: string | null;
  tdsTransId: string | null;
  docNo: string | null;
  msgTyp: string | null;
  message: string | null;
  createdAt: Date;
  updatedAt: Date;
}

interface Form16SapResponseCreationAttributes
  extends Optional<
    Form16SapResponseAttributes,
    | 'id'
    | 'trnsUniqNo'
    | 'tdsTransId'
    | 'docNo'
    | 'msgTyp'
    | 'message'
    | 'createdAt'
    | 'updatedAt'
  > {}

class Form16SapResponse
  extends Model<Form16SapResponseAttributes, Form16SapResponseCreationAttributes>
  implements Form16SapResponseAttributes
{
  public id!: number;
  public trnsUniqNo!: string | null;
  public tdsTransId!: string | null;
  public docNo!: string | null;
  public msgTyp!: string | null;
  public message!: string | null;
  public createdAt!: Date;
  public updatedAt!: Date;
}

Form16SapResponse.init(
  {
    id:               { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true },
    trnsUniqNo:       { type: DataTypes.STRING(200), allowNull: true, field: 'trns_uniq_no' },
    tdsTransId:       { type: DataTypes.STRING(200), allowNull: true, field: 'tds_trns_id' },
    docNo:            { type: DataTypes.STRING(200), allowNull: true, field: 'doc_no' },
    msgTyp:           { type: DataTypes.STRING(20),  allowNull: true, field: 'msg_typ' },
    message:          { type: DataTypes.TEXT,        allowNull: true },
    createdAt:        { type: DataTypes.DATE, allowNull: false, field: 'created_at' },
    updatedAt:        { type: DataTypes.DATE, allowNull: false, field: 'updated_at' },
  },
  {
    sequelize,
    tableName: 'form16_sap_responses',
    timestamps: true,
    underscored: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at',
  }
);

export { Form16SapResponse };
