import { Model, DataTypes, Sequelize } from 'sequelize';

export interface EorChecklistItemAttributes {
    id: string;
    checklistId: string;
    itemType: string;
    description: string;
    isCompliant: boolean;
    remarks: string | null;
    proofDocumentId: string | null;
}

export interface EorChecklistItemInstance extends Model<EorChecklistItemAttributes>, EorChecklistItemAttributes { }

export default (sequelize: Sequelize) => {
    const EorChecklistItem = sequelize.define<EorChecklistItemInstance>('EorChecklistItem', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true
        },
        checklistId: {
            type: DataTypes.UUID,
            allowNull: false,
            references: {
                model: 'eor_checklists',
                key: 'id'
            }
        },
        itemType: {
            type: DataTypes.STRING,
            allowNull: false
        },
        description: {
            type: DataTypes.TEXT,
            allowNull: false
        },
        isCompliant: {
            type: DataTypes.BOOLEAN,
            defaultValue: false
        },
        remarks: {
            type: DataTypes.TEXT,
            allowNull: true
        },
        proofDocumentId: {
            type: DataTypes.UUID,
            allowNull: true
        }
    }, {
        tableName: 'eor_checklist_items',
        timestamps: true
    });

    (EorChecklistItem as any).associate = (models: any) => {
        EorChecklistItem.belongsTo(models.EorChecklist, { foreignKey: 'checklistId', as: 'checklist' });
    };

    return EorChecklistItem;
};
