import { ApiProperty } from '@nestjs/swagger';
import { IsIn } from 'class-validator';
import {
  TASK_LIST_SORTABLE_ATTRIBUTES,
  USER_LICENSE_STATUS,
} from '../../../constants';
import { USER_ROLES } from '../../../constants';

export class ConfirmRequest {
  @ApiProperty()
  token: string;
}

export class ConfirmResponse {}

export class User {
  @ApiProperty()
  id: number;

  @ApiProperty()
  name: string;

  @ApiProperty({ description: 'none/author/typist' })
  role: string;

  @ApiProperty({ required: false })
  authorId?: string | undefined;

  @ApiProperty()
  typistGroupName: string[];

  @ApiProperty()
  email: string;

  @ApiProperty()
  emailVerified: boolean;

  @ApiProperty()
  autoRenew: boolean;

  @ApiProperty()
  licenseAlert: boolean;

  @ApiProperty()
  notification: boolean;

  @ApiProperty()
  encryption: boolean;

  @ApiProperty()
  prompt: boolean;

  @ApiProperty({ required: false })
  expiration?: string | undefined;

  @ApiProperty({ required: false })
  remaining?: number | undefined;

  @ApiProperty({
    description: `${Object.values(USER_LICENSE_STATUS).join('/')}`,
  })
  @IsIn(Object.values(USER_LICENSE_STATUS), {
    message: 'invalid license status',
  })
  licenseStatus: string;
}

export class GetUsersResponse {
  @ApiProperty({ type: [User] })
  users: User[];
}

export class SignupRequest {
  @ApiProperty()
  name: string;

  @ApiProperty({ description: 'none/author/typist' })
  @IsIn([USER_ROLES.NONE, USER_ROLES.AUTHOR, USER_ROLES.TYPIST])
  role: string;

  @ApiProperty({ required: false })
  authorId?: string | undefined;

  @ApiProperty({ required: false })
  typistGroupId?: number | undefined;

  @ApiProperty()
  email: string;

  @ApiProperty()
  autoRenew: boolean;

  @ApiProperty()
  licenseAlert: boolean;

  @ApiProperty()
  notification: boolean;
}

export class SignupResponse {}

export class OptionItem {
  @ApiProperty({
    minLength: 1,
    maxLength: 16,
    description: 'Option Itemのラベル',
  })
  label: string;
  @ApiProperty({ description: '項目タイプ 1:Blank/2:Default/3:前の値' })
  initialValueType: number;
  @ApiProperty({
    minLength: 1,
    maxLength: 20,
    description: 'typeでDefaultを選択した場合のデフォルト値',
  })
  defaultValue: string;
}
export class OptionItemList {
  @ApiProperty()
  workTypeId: string;
  @ApiProperty({
    type: [OptionItem],
    maxItems: 10,
    description: '1WorkTypeIDにつき、10個まで登録可能',
  })
  optionItemList: OptionItem[];
}

export class GetRelationsResponse {
  @ApiProperty({
    description: 'ログインしたユーザーのAuthorID（Authorでない場合は空文字）',
  })
  authorId: string;
  @ApiProperty({ description: '属しているアカウントのAuthorID List(全て)' })
  authorIdList: string[];
  @ApiProperty({
    type: [OptionItemList],
    maxItems: 20,
    description: 'アカウントに設定されているWorktypeIDのリスト（最大20個）',
  })
  workTypeList: OptionItemList[];
  @ApiProperty({ description: 'ユーザーが音声ファイルを暗号化するかどうか' })
  isEncrypted: boolean;
  @ApiProperty({
    description: 'ユーザーが暗号化を掛ける場合のパスワード',
    nullable: true,
  })
  encryptionPassword?: string | undefined;
  @ApiProperty({
    description:
      'アカウントがデフォルトで利用するWorkTypeID（アカウントに紐づくWorkTypeIDから一つ指定）',
  })
  activeWorktype: string;
  @ApiProperty({ description: '録音形式: DSS/DS2(SP)/DS2(QP)： DS2固定' })
  audioFormat: string;
  @ApiProperty({
    description:
      'デバイス上で自動的にWorkTypeの選択画面を表示するかどうかのユーザーごとの設定（Authorでない場合はfalse）',
  })
  prompt: boolean;
}

export class PostSortCriteriaRequest {
  @ApiProperty({ description: 'ASC/DESC' })
  @IsIn(['ASC', 'DESC'], { message: 'invalid direction' })
  direction: string;

  @ApiProperty({
    description: `${TASK_LIST_SORTABLE_ATTRIBUTES.join('/')}`,
  })
  @IsIn(TASK_LIST_SORTABLE_ATTRIBUTES, {
    message: 'invalid attributes',
  })
  paramName: string;
}

export class PostSortCriteriaResponse {}

export class GetSortCriteriaRequest {}

export class GetSortCriteriaResponse {
  @ApiProperty({ description: 'ASC/DESC' })
  direction: string;

  @ApiProperty({
    description: `${TASK_LIST_SORTABLE_ATTRIBUTES.join('/')}`,
  })
  paramName: string;
}

export class PostUpdateUserRequest {
  @ApiProperty()
  id: number;

  @ApiProperty({ description: 'none/author/typist' })
  @IsIn([USER_ROLES.NONE, USER_ROLES.AUTHOR, USER_ROLES.TYPIST])
  role: string;

  @ApiProperty({ required: false })
  authorId?: string | undefined;

  @ApiProperty()
  autoRenew: boolean;

  @ApiProperty()
  licenseAlart: boolean;

  @ApiProperty()
  notification: boolean;

  @ApiProperty({ required: false })
  encryption?: boolean | undefined;

  @ApiProperty({ required: false })
  encryptionPassword?: string | undefined;

  @ApiProperty({ required: false })
  prompt?: boolean | undefined;
}

export class PostUpdateUserResponse {}
