/**
 * @aurora-catalyst-generated
 * @source cliter/o-auth/application.aurora.yaml
 */
import { OAuthApplicationClientModel } from '@app/o-auth/application-client';
import { OAuthClientModel } from '@app/o-auth/client';
import { Auditable } from '@aurorajs.dev/core-back';
import { DataTypes } from 'sequelize';
import { BelongsToMany, Column, Model, Table } from 'sequelize-typescript';

@Auditable()
@Table({
  modelName: 'OAuthApplication',
  tableName: 'o_auth_application',
  freezeTableName: true,
  timestamps: false,
  indexes: [
    {
      fields: ['row_id'],
      unique: true,
    },
    {
      fields: ['code'],
      unique: true,
    },
  ],
})
export class OAuthApplicationModel extends Model<OAuthApplicationModel> {
  @Column({
    field: 'id',
    primaryKey: true,
    allowNull: false,
    type: DataTypes.UUID,
  })
  id: string;

  @Column({
    field: 'row_id',
    autoIncrement: true,
    allowNull: false,
    type: DataTypes.BIGINT,
  })
  rowId: number;

  @Column({
    field: 'code',
    allowNull: false,
    type: DataTypes.STRING(64),
  })
  code: string;

  @Column({
    field: 'name',
    allowNull: false,
    type: DataTypes.STRING(128),
  })
  name: string;

  @Column({
    field: 'secret',
    allowNull: false,
    type: DataTypes.STRING(128),
  })
  secret: string;

  @Column({
    field: 'is_master',
    allowNull: false,
    type: DataTypes.BOOLEAN,
    defaultValue: false,
  })
  isMaster: boolean;

  @BelongsToMany(() => OAuthClientModel, {
    through: () => OAuthApplicationClientModel,
    uniqueKey: 'Uq01OAuthApplicationClient',
    constraints: false,
  })
  clients: OAuthClientModel[];

  @Column({
    field: 'created_at',
    allowNull: true,
    type: DataTypes.DATE,
  })
  createdAt: string;

  @Column({
    field: 'updated_at',
    allowNull: true,
    type: DataTypes.DATE,
  })
  updatedAt: string;

  @Column({
    field: 'deleted_at',
    allowNull: true,
    type: DataTypes.DATE,
  })
  deletedAt: string;
}
