import { ViewColumn, ViewEntity } from "typeorm";

@ViewEntity({
  expression: `SELECT 
    \`profileId\`,\`period\`,\`year\`,\`posMaster\`.\`orgRootId\`,\`posMaster\`.\`orgChild1Id\`,\`posMaster\`.\`orgChild2Id\`,\`posMaster\`.\`orgChild3Id\`,\`posMaster\`.\`orgChild4Id\`, COUNT(*) AS recordCount, SUM(pointSum) AS totalPointSum, SUM(pointSum) / COUNT(*) AS result
    FROM\`profileAssessment\` 
    LEFT JOIN \`profile\` ON \`profileAssessment\`.\`profileId\` = \`profile\`.\`id\`
    LEFT JOIN \`posMaster\` ON \`profile\`.\`id\` = \`posMaster\`.\`current_holderId\`
    LEFT JOIN \`orgRevision\` ON \`posMaster\`.\`orgRevisionId\` = \`orgRevision\`.\`id\`
    WHERE \`period\` Is not null
    AND \`orgRevision\`.\`orgRevisionIsCurrent\` = true
    GROUP BY\`profileId\`,\`period\`,\`year\`,\`orgRootId\`,\`orgChild1Id\`,\`orgChild2Id\`,\`orgChild3Id\`,\`orgChild4Id\`
    ORDER BY\`year\`  desc ,\`period\` asc
    `,
})
export class viewProfileEvaluation {
  @ViewColumn()
  profileId: string;
  @ViewColumn()
  period: string;
  @ViewColumn()
  year: number;
  @ViewColumn()
  orgRootId: string;
  @ViewColumn()
  orgChild1Id: string;
  @ViewColumn()
  orgChild2Id: string;
  @ViewColumn()
  orgChild3Id: string;
  @ViewColumn()
  orgChild4Id: string;
  @ViewColumn()
  recordCount: number;
  @ViewColumn()
  totalPointSum: number;
  @ViewColumn()
  result: number;
}
