import { ApiProperty } from '@nestjs/swagger';
import { LicenseFeatures } from '../../asset/logic/LicenseFeatures';
import {
  IsBoolean,
  IsInt,
  IsObject,
  IsOptional,
  IsString,
} from 'class-validator';

export class ProjectLicenseShortDTO {
  @ApiProperty({})
  id: number;

  @ApiProperty({})
  name: string;

  @ApiProperty({})
  title: string;

  @ApiProperty({})
  startAt: string | null;

  @ApiProperty({})
  till: string | null;

  @ApiProperty({})
  isTrial: boolean;
}

export class ProjectLicenseDTO extends ProjectLicenseShortDTO {
  @ApiProperty({})
  features: LicenseFeatures;
}

export type ProjectLicenseType = {
  id: number;
  name: string;
  title: string;
  features: LicenseFeatures;
  priority: number;
};

export class ProjectLicenseTariffDTO {
  @ApiProperty({})
  id: number;

  @ApiProperty({})
  title: string;

  @ApiProperty({})
  licenseTypeName: string;

  @ApiProperty({})
  monthNum: number;

  @ApiProperty({})
  priceRub: string;

  @ApiProperty({})
  priceUsd: string;

  @ApiProperty({})
  features: LicenseFeatures;
}

export class LicenseTypeDTO {
  @ApiProperty({})
  @IsInt()
  id: number;

  @ApiProperty({})
  @IsString()
  name: string;

  @ApiProperty({})
  @IsString()
  title: string;

  @ApiProperty({})
  @IsObject()
  features: string;

  @ApiProperty({})
  @IsInt()
  priority: number;

  @ApiProperty({ required: false, type: Date })
  @IsOptional()
  deletedAt?: string;
}

export class ProjectLicenseDBDTO {
  @ApiProperty({})
  @IsInt()
  id: number;

  @ApiProperty({})
  @IsString()
  projectId: string;

  @ApiProperty({})
  @IsInt()
  licenseTypeId: number;

  @ApiProperty({ type: Date })
  startAt: string;

  @ApiProperty({ type: Date })
  updatedAt: string;

  @ApiProperty({ type: String || null })
  till: string | null;

  @ApiProperty({})
  @IsString()
  paymentInfo: string;

  @ApiProperty({})
  @IsObject()
  features: Record<string, any> | null;

  @ApiProperty({})
  @IsString()
  comment: string;

  @ApiProperty({})
  @IsBoolean()
  isTrial: boolean;

  @ApiProperty({ required: false, type: Date })
  @IsOptional()
  deletedAt?: string;
}

export class AcceptSyncDTO {
  @ApiProperty({
    type: LicenseTypeDTO,
    isArray: true,
  })
  licenseTypes: LicenseTypeDTO[];

  @ApiProperty({
    type: ProjectLicenseDBDTO,
    isArray: true,
  })
  projectLicenses: ProjectLicenseDBDTO[];

  @ApiProperty({})
  @IsString()
  key: string;
}
