unit TimeEntry.Service;

interface

uses
  System.Generics.Collections,
  XData.Service.Common,
  Bcl.Types.Nullable,
  Aurelius.Mapping.Attributes;

const
  API_MODEL = 'Api';

type
  TTimeEntry = class
  public
    entryId: Integer;
    taskDate: string;
    taskId: string;
    taskDisplay: string;
    hours: Nullable<Double>;
    taskTime: string;
    place: string;
    placeDesc: string;
    category: string;
    categoryDesc: string;
    summary: string;
  end;

  TTimeEntryTaskOption = class
  public
    taskId: string;
    taskDisplay: string;
  end;

  TTimeEntryCategoryOption = class
  public
    code: string;
    codeDesc: string;
  end;

  TTimeEntriesResponse = class
  public
    userName: string;
    count: Integer;
    items: TList<TTimeEntry>;
    taskOptions: TList<TTimeEntryTaskOption>;
    categoryOptions: TList<TTimeEntryCategoryOption>;
    placeOptions: TList<TTimeEntryCategoryOption>;
    constructor Create;
    destructor Destroy; override;
  end;

  TTimeEntrySave = class
  public
    entryId: string;
    userId: string;
    taskDate: string;
    taskId: string;
    hours: Double;
    taskTime: string;
    place: string;
    category: string;
    summary: string;
  end;


  TTimeEntryFieldSave = class
  public
    entryId: Integer;
    userId: string;
    fieldName: string;
    value: string;
  end;

  type
  TTaskPickerOption = class
  public
    value: string;
    display: string;
  end;

  TTaskPickerOptionsResponse = class
  public
    options: TList<TTaskPickerOption>;
    constructor Create;
    destructor Destroy; override;
  end;

  [ServiceContract, Model(API_MODEL)]
  ITimeEntryService = interface(IInvokable)
    ['{B18BCD1E-B19A-4D25-BBA9-50A24FC4C690}']
    [HttpGet] function GetTimeEntries(userId, startDate, endDate: string): TTimeEntriesResponse;
    [HttpPost] function AddTimeEntry(userId, taskDate: string): string;
    [HttpPost] function SaveTimeEntry(Item: TTimeEntrySave): Boolean;
    [HttpPost] function SaveTimeEntryField(Item: TTimeEntryFieldSave): Boolean;
    [HttpPost] function DeleteTimeEntry(userId: string; entryId: Integer): Boolean;
    function GetTaskPickerCustomers(userId: string): TTaskPickerOptionsResponse;
    function GetTaskPickerProjects(userId, customerId: string): TTaskPickerOptionsResponse;
    function GetTaskPickerTasks(userId, projectId: string): TTaskPickerOptionsResponse;
  end;

implementation

constructor TTimeEntriesResponse.Create;
begin
  inherited;
  items := TList<TTimeEntry>.Create;
  taskOptions := TList<TTimeEntryTaskOption>.Create;
  categoryOptions := TList<TTimeEntryCategoryOption>.Create;
  placeOptions := TList<TTimeEntryCategoryOption>.Create;
end;

destructor TTimeEntriesResponse.Destroy;
begin
  items.Free;
  taskOptions.Free;
  categoryOptions.Free;
  placeOptions.Free;
  inherited;
end;

constructor TTaskPickerOptionsResponse.Create;
begin
  inherited;
  options := TList<TTaskPickerOption>.Create;
end;

destructor TTaskPickerOptionsResponse.Destroy;
begin
  options.Free;
  inherited;
end;

initialization
  RegisterServiceType(TypeInfo(ITimeEntryService));

end.
