import { PgUserInfoMstr, PgUserFileMapping } from './employee.model';

export enum InnovationType {
  idea = 'idea',
  poc = 'poc',
  ideaPOC = 'ideaPOC'
}

export interface Idea {
  innovationId: number;
  title: string;
  description: string;
  commments: string[];
  status: InnovationStatusNames;
  creator: User;
  category: { id: number; categoryName: string; };
  focal: { id: number; focalName: string; focalUser: User };
  reviewer: User;
  file: FileDescriptor;
  coInnovators: User[];
  poc: POC[];
  createdBy: string;
  createdDt: number;
  updatedBy: string;
  updatedDt: number;
}

interface User {
  id: number;
  fullName: string;
  profImgFileId: number;
}

interface FileDescriptor {
  id: number;
  fileName: string;
}

export interface File {
  fileId: number;
  fileName: string;
  contentType: string;
  fileContent: Blob;
}

interface Innovator {
  innovatorId: number;
  innovationId: number;
  pgUserInfoMstr: PgUserInfoMstr;
}

interface PgInnovationFocalMstr {
  focalId: number;
  focalName: string;
  pgUserInfoMstr: PgUserInfoMstr;
  createdBy: string;
  createdDate: number;
  updatedBy: string;
  updatedDate: number;
}

interface PgInnovationCategoryMstr {
  categoryId: number;
  category: string;
  createdBy: string;
  createdDate: number;
  updatedBy: string;
  updatedDate: number;
}

export interface InnovationIdeaResponse {
  status: string;
  error: string;
  pgUserInfoDtls: number;
  completedCount: number;
  inprogressCount: number;
  overdueCount: number;
  wishlistCount: number;
  innovationCount: number;
  componentCount: number;
}

export interface InnovationIdeaPayload {
  submitterId: number;
  userInfoMstrId: number;
  title?: string;
  category?: string;
  description?: string;
  innovationFocal?: number;
  fileId?: number;
  fileName?: string;
  innovatorIds?: number[];
  isExistingIdea?: boolean;
  createdBy?: string;
  updatedBy?: string;
}

export interface InnovationIdeaCreatePayload extends InnovationIdeaPayload {
  title: string;
  category: string;
  description: string;
  innovationFocal: number;
}

export interface InnovationIdeaUpdatePayload extends InnovationIdeaPayload {
  innovationId: number;
  status: InnovationStatusNames;
  reviewer?: number;
  comments?: string;
  pocDescription?: string;
  pocTitle?: string;
  pocFileId?: number;
  pocFileName?: string;
}

export interface InnovationPOCUpdatePayload {
  submitterId: number;
  userInfoMstrId: number;
  innovationId: number;
  status: POCStatus;
}

export interface InnovationPOCPayload {
  innovationId: number;
  pocTitle: string;
  pocDescription: string;
  pocFileId?: number;
  pocFileName?: string;
}
export interface PgFileSystem {
  fileId: number;
  fileContent: string;
  fileName: string;
  createdDt: number;
}

export enum InnovationStatus {
  Created = 'CREATED',
  Submitted = 'SUBMITTED',
  Closed = 'CLOSED',
  InProgress = 'ASSIGNED',
  Rejected = 'REJECTED',
  Rework = 'REWORK',
  TakeOff = 'TAKE_OFF'
}

export enum POCStatus {
  Created = 'POC_IN_PROGRESS',
  Submitted = 'POC_SUBMITTED',
  Closed = 'POC_CLOSED',
  InProgress = 'POC_ASSIGNED',
  Rejected = 'POC_REJECTED',
  Rework = 'POC_REWORK',
  TakeOff = 'POC_APPROVED'
}

export type InnovationStatusNames = InnovationStatus | POCStatus;

export interface InnovationStatusInfo {
  level: number;
  name: InnovationStatus;
  label: string;
  class: string;
}

/*
  The classes are stored as sass global variables in the following path:
  app/employee/shared/stylesheets/innovationVars.scss
  If a class name is updated the global var names must be updated too.
*/

export const InnovationStatusObject = {
  Created: { level: 0, name: InnovationStatus.Created, label: 'Created', class: 'created' },
  Submitted: { level: 1, name: InnovationStatus.Submitted, label: 'Submitted', class: 'submitted' },
  Closed: { level: 1, name: InnovationStatus.Closed, label: 'Closed', class: 'closed' },
  InProgress: { level: 2, name: InnovationStatus.InProgress, label: 'In Progress', class: 'inprogress' },
  Rejected: { level: 3, name: InnovationStatus.Rejected, label: 'Rejected', class: 'rejected' },
  Rework: { level: 3, name: InnovationStatus.Rework, label: 'Rework', class: 'rework' },
  TakeOff: { level: 3, name: InnovationStatus.TakeOff, label: 'Take-Off', class: 'takeoff' },
};

export function getStatusObject(status: string) {
  if (Object.values(InnovationStatus).includes(status)) {
    return InnovationStatusObject[Object.keys(InnovationStatus).find(key => InnovationStatus[key] === status)];
  } else if (Object.values(POCStatus).includes(status)) {
    return InnovationStatusObject[Object.keys(POCStatus).find(key => POCStatus[key] === status)];
  } else { return null; }
}

export interface POC {
  pocId: number;
  innovationId: number;
  pocTitle: string;
  pocDescription: string;
  pocFile?: FileDescriptor;
  createdBy?: string;
  createdDt?: number;
}

export interface InnovationIdeaDetailsResponse {
  ideasList: Idea[];
  pocList: POC[];
}

export interface ReviewerDetails {
   creatorId: number;
   reviewerId: number;
   innovationId: number;
}
