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

export interface ProjectRoleMasterAttributes {
    id: number;
    role: string;
    is_active: boolean;
}

interface ProjectRoleMasterCreationAttributes extends Optional<ProjectRoleMasterAttributes, 'id'> {}

export class ProjectRoleMaster
    extends Model<ProjectRoleMasterAttributes, ProjectRoleMasterCreationAttributes>
    implements ProjectRoleMasterAttributes 
{
    public id!: number;
    public role!: string;
    public is_active!: boolean;

    public toJSON(): ProjectRoleMasterAttributes {
        return {
            ...super.toJSON(),
            id: this.id,
            role: this.role,
            is_active: this.is_active,
        };
    }
}

export default (sequelize: Sequelize, dataTypes: typeof DataTypes) => {
    ProjectRoleMaster.init(
        {
            id: {
                type: dataTypes.INTEGER,
                autoIncrement: true,
                primaryKey: true,
            },
            role: {
                type: dataTypes.STRING,
                allowNull: false,
            },
            is_active: {
                type: dataTypes.BOOLEAN,
                allowNull: false,
                defaultValue: true,
            },
        },
        {
            sequelize,
            modelName: 'ProjectRoleMaster',
            tableName: 'project_role_masters',
            timestamps: true,
        }
    );

    return ProjectRoleMaster;
};
