unit Api.Service;

interface

uses
  XData.Service.Common,
  System.Generics.Collections,
  System.Classes,
  System.SysUtils,
  Aurelius.Mapping.Attributes,
  System.JSON,
  Common.Logging;

const
  API_MODEL = 'Api';

type
  TTaskItem = class
  public
    taskItemId: integer;
    taskId: string;
    itemNum: integer;
    application: string;
    version: string;
    taskDate: TDateTime;
    reportedBy: string;
    assignedTo: string;
    status: string;
    statusDate: TDateTime;
    fixedVersion: string;
    formSection: string;
    issue: string;
    notes: string;
  end;

  TTaskHeader = class
  public
    taskId: string;
    parentId: string;
    taskNumber: string;
    projectName: string;
    subject: string;
    title: string;
  end;

  TTaskUserOption = class
  public
    name: string;
  end;

  TTaskApplicationOption = class
  public
    name: string;
  end;

  TTaskItemCode = class
  public
    code: string;
    codeDesc: string;
    codeType: string;
  end;

  TTaskItemsResponse = class
  public
    count: integer;
    task: TTaskHeader;
    items: TList<TTaskItem>;
    applicationOptions: TList<TTaskApplicationOption>;
    reportedByOptions: TList<TTaskUserOption>;
    assignedToOptions: TList<TTaskUserOption>;
    statusOptions: TList<TTaskItemCode>;
    constructor Create;
    destructor Destroy; override;
  end;

  TTaskUserOptionsResponse = class
  public
    assignedToOptions: TList<TTaskUserOption>;
    constructor Create;
    destructor Destroy; override;
  end;

  TTaskApplicationOptionsResponse = class
  public
    applicationOptions: TList<TTaskApplicationOption>;
    constructor Create;
    destructor Destroy; override;
  end;

  TTaskRowSave = class
  public
    taskItemId: integer;
    taskId: string;
    taskNum: integer;
    application: string;
    version: string;
    taskDate: string;
    reportedBy: string;
    assignedTo: string;
    status: string;
    statusDate: string;
    fixedVersion: string;
    formSection: string;
    issue: string;
    notes: string;
  end;

type
  [ServiceContract, Model(API_MODEL)]
  IApiService = interface(IInvokable)
    ['{0EFB33D7-8C4C-4F3C-9BC3-8B4D444B5F69}']
    function GetTaskItems(taskId: string): TTaskItemsResponse;
    [HttpPost] function AddTaskRow(taskId: string; insertAfterItemNum: Integer): Boolean;
    [HttpPost] function SaveTaskRow(Item: TTaskRowSave): Boolean;
    [HttpPost] function AddAssignedName(taskId: string; name: string): TTaskUserOptionsResponse;
    [HttpPost] function RenameAssignedName(taskId: string; oldName: string; newName: string): TTaskUserOptionsResponse;
    [HttpPost] function DeleteAssignedName(taskId: string; name: string): TTaskUserOptionsResponse;
    [HttpPost] function AddApplicationName(taskId: string; name: string): TTaskApplicationOptionsResponse;
    [HttpPost] function RenameApplicationName(taskId: string; oldName: string; newName: string): TTaskApplicationOptionsResponse;
    [HttpPost] function DeleteApplicationName(taskId: string; name: string): TTaskApplicationOptionsResponse;
    procedure MoveTaskRow(const taskId: Integer; const taskItemId: Integer; const newItemNum: Integer);
    function DeleteTaskRow(const taskId: Integer; const taskItemId: Integer): Boolean;
  end;

implementation

constructor TTaskItemsResponse.Create;
begin
  inherited;
  items := TList<TTaskItem>.Create;
  applicationOptions := TList<TTaskApplicationOption>.Create;
  reportedByOptions := TList<TTaskUserOption>.Create;
  assignedToOptions := TList<TTaskUserOption>.Create;
  statusOptions := TList<TTaskItemCode>.Create;
end;

destructor TTaskItemsResponse.Destroy;
begin
  items.Free;
  applicationOptions.Free;
  reportedByOptions.Free;
  assignedToOptions.Free;
  statusOptions.Free;
  inherited;
end;

constructor TTaskUserOptionsResponse.Create;
begin
  inherited;
  assignedToOptions := TList<TTaskUserOption>.Create;
end;

destructor TTaskUserOptionsResponse.Destroy;
begin
  assignedToOptions.Free;
  inherited;
end;

constructor TTaskApplicationOptionsResponse.Create;
begin
  inherited;
  applicationOptions := TList<TTaskApplicationOption>.Create;
end;

destructor TTaskApplicationOptionsResponse.Destroy;
begin
  applicationOptions.Free;
  inherited;
end;

initialization
  RegisterServiceType(TypeInfo(IApiService));

end.
