import {sequelize} from "../app";
import {DataTypes, InferAttributes, InferCreationAttributes, Model} from "sequelize";

export enum Rank {
    USER = "user",
    TEAM_MEMBER = "team",
    ADMIN = "admin"
}

export interface IUser extends Model<InferAttributes<IUser>, InferCreationAttributes<IUser>> {
    clientId: number
    username: string
    locale?: string
    rank?: Rank
    avatarId?: string
    accessToken: string
    refreshToken: string
    refreshDate?: Date
}

const UserSchema = sequelize.define<IUser>('users', {
    clientId: {
        type: DataTypes.BIGINT,
        allowNull: false,
        primaryKey: true
    },
    username: {
        type: DataTypes.STRING,
        defaultValue: "User#0001"
    },
    locale: {
        type: DataTypes.STRING,
        defaultValue: "en"
    },
    rank: {
        type: DataTypes.STRING,
        defaultValue: Rank.USER
    },
    avatarId: {
        type: DataTypes.STRING,
        defaultValue: "590962a0d694945a779054cd078a7efd"
    },
    accessToken: {
        type: DataTypes.STRING,
        allowNull: false
    },
    refreshToken: {
        type: DataTypes.STRING,
        allowNull: false
    },
    refreshDate: {
        type: DataTypes.DATE,
        allowNull: false
    }
});

export const User = UserSchema;