import { AutoIncrement, Column, DataType, Model, PrimaryKey, Table } from "sequelize-typescript";
import { ROLE, STATE } from "../types/common.types";

export interface AuthorityCreateSchema {
    email?: string,
    role?: ROLE,
    status?: STATE
}

@Table({
    tableName: 'authority',
    timestamps: true,
    paranoid: true
})
export default class Authority extends Model<Authority,AuthorityCreateSchema> {
    @PrimaryKey
    @AutoIncrement
    @Column({
        type: DataType.INTEGER({ length: 11 }),
    })
    id!: number;

    @Column({
        type: DataType.STRING({ length: 100 }),
        validate: {
            isEmail: true,
        },
        allowNull: false,
        unique : true
    })
    email!: number;

    @Column({
        type: DataType.ENUM(...Object.keys(ROLE)),
        defaultValue: ROLE.ADMIN
    })
    role!: number;

    @Column({
        type: DataType.ENUM(...Object.keys(STATE)),
        defaultValue: STATE.ACTIVE
    })
    status!: STATE;
}