import { Injectable } from '@nestjs/common';
import { RedminePublicUrlConverter } from '../converters/redmine-public-url.converter';
import { RedmineTypes } from '../models/redmine-types';
import { IssueEnhancerInterface } from './issue-enhancer-interface';

@Injectable()
export class IssueUrlEnhancer implements IssueEnhancerInterface {
  name = 'issue-url';

  constructor(private redminePublicUrlConverter: RedminePublicUrlConverter) {}

  async enhance(
    issue: RedmineTypes.Issue,
  ): Promise<RedmineTypes.Issue & Record<string, any>> {
    const res: RedmineTypes.Issue & Record<string, any> = issue;
    if (!issue || !issue.id) return issue;
    res['url'] = {
      url: this.redminePublicUrlConverter.getUrl(issue.id),
      fullHref: this.redminePublicUrlConverter.getHtmlHref(issue),
      minHref: this.redminePublicUrlConverter.getMinHtmlHref(issue.id),
    };
    return res;
  }
}
