Files
territory-autobattler/microservices/LocationsApi/Models/Dto.cs
T
2026-05-19 15:40:31 -05:00

89 lines
3.3 KiB
C#

namespace LocationsApi.Models;
public class UpsertLocationRequest
{
public int Q { get; set; }
public int R { get; set; }
public string Terrain { get; set; } = "Field";
public string? Label { get; set; }
public int Level { get; set; } = 1;
}
public class ClaimLocationRequest
{
public int Q { get; set; }
public int R { get; set; }
}
public class BuildLocationRequest
{
public int Q { get; set; }
public int R { get; set; }
public string BuildingType { get; set; } = "LogCamp";
}
public class LocationResponse
{
public string Id { get; set; } = "";
public int Q { get; set; }
public int R { get; set; }
public string Terrain { get; set; } = "Field";
public string Kind { get; set; } = "Open";
public string? OwnerUsername { get; set; }
public string? Label { get; set; }
public int Level { get; set; }
public string? BuildingType { get; set; }
public string? BuildingStatus { get; set; }
public DateTime? BuildingStartedAtUtc { get; set; }
public DateTime? BuildingCompletesAtUtc { get; set; }
public DateTime? BuildingBuiltAtUtc { get; set; }
public DateTime? HomeAssignedAtUtc { get; set; }
public DateTime UpdatedAtUtc { get; set; }
public bool IsVisible { get; set; } = true;
public static LocationResponse FromLocation(Location location, bool revealDetails = true) => new()
{
Id = location.Id,
Q = location.Q,
R = location.R,
Terrain = location.Terrain,
Kind = location.Kind,
OwnerUsername = location.OwnerUsername,
Label = location.Label,
Level = location.Level,
BuildingType = revealDetails ? location.BuildingType : null,
BuildingStatus = revealDetails && (location.BuildingType == "LogCamp" || location.BuildingType == "Mine" || location.BuildingType == "Barracks" || location.BuildingType == "Farm") && string.IsNullOrWhiteSpace(location.BuildingStatus)
? "Built"
: revealDetails ? location.BuildingStatus : null,
BuildingStartedAtUtc = revealDetails ? location.BuildingStartedAtUtc : null,
BuildingCompletesAtUtc = revealDetails ? location.BuildingCompletesAtUtc : null,
BuildingBuiltAtUtc = revealDetails ? location.BuildingBuiltAtUtc : null,
HomeAssignedAtUtc = location.HomeAssignedAtUtc,
UpdatedAtUtc = location.UpdatedAtUtc,
IsVisible = true
};
public static LocationResponse FromIntel(LocationIntel intel) => new()
{
Id = intel.Id,
Q = intel.Q,
R = intel.R,
Terrain = intel.Terrain,
Kind = intel.Kind,
OwnerUsername = intel.OwnerUsername,
Label = intel.Label,
Level = intel.Level,
BuildingType = intel.BuildingType,
BuildingStatus = (intel.BuildingType == "LogCamp" || intel.BuildingType == "Mine" || intel.BuildingType == "Barracks" || intel.BuildingType == "Farm") && string.IsNullOrWhiteSpace(intel.BuildingStatus)
? "Built"
: intel.BuildingStatus,
BuildingStartedAtUtc = intel.BuildingStartedAtUtc,
BuildingCompletesAtUtc = intel.BuildingCompletesAtUtc,
BuildingBuiltAtUtc = intel.BuildingBuiltAtUtc,
HomeAssignedAtUtc = intel.HomeAssignedAtUtc,
UpdatedAtUtc = intel.ObservedAtUtc,
IsVisible = true
};
}