import { AutoIncrement, Column, CreatedAt, DataType, Min, Model, PrimaryKey, Table, UpdatedAt } from "sequelize-typescript";
import { VISIBILITY } from "../types/common.types";

interface CreateParams {
    channel_id : number;
    source : string;
    rank?: number;
    status ?: VISIBILITY 
}

@Table({
    tableName: 'source',
    timestamps: true,
    paranoid: true,
})
export default class Source extends Model<Source,CreateParams> {
    @PrimaryKey
    @AutoIncrement
    @Column({
        type: DataType.INTEGER({ length: 11 }),
    })
    id!: number;

    @Column({
        type: DataType.INTEGER({ length: 11 })
    })
    channel_id !: number;

    @Column({
        type: DataType.TEXT,
        validate : {
            isUrl: true,
            notEmpty:true,
        },
        allowNull : false,
    })
    source !: string;


    @Column({
        type: DataType.INTEGER({ length: 3 }),
        validate: {
            min: 0,
            max: 999,
        },
        defaultValue: 0
    })
    rank !: number;

    @Column({
        type: DataType.ENUM(...Object.values(VISIBILITY)),
        defaultValue: VISIBILITY.VISIBLE
    })
    status !: VISIBILITY;
}