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: Variant;
    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;

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

  TTaskItemsResponse = class
  public
    count: integer;
    task: TTaskHeader;
    items: TList<TTaskItem>;
    reportedByOptions: TList<TTaskUserOption>;
    assignedToOptions: TList<TTaskUserOption>;
    statusOptions: TList<TTaskItemCode>;
    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;
    function TestApi(messageText: string): TJSONObject;
    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;
  reportedByOptions := TList<TTaskUserOption>.Create;
  assignedToOptions := TList<TTaskUserOption>.Create;
  statusOptions := TList<TTaskItemCode>.Create;
end;

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

initialization
  RegisterServiceType(TypeInfo(IApiService));

end.
