using System.Text.Json.Serialization;

namespace ApiOPE.Contracts;

public sealed record OpeFieldValue(
    [property: JsonPropertyName("type")] string Type,
    [property: JsonPropertyName("value")] string Value);

public sealed record OpeDataEnvelope(
    [property: JsonPropertyName("data")] IReadOnlyDictionary<string, OpeFieldValue> Data);

public sealed record OpeVersionResponse(
    [property: JsonPropertyName("version")] string Version);

public sealed record OpeTypedInfo(
    [property: JsonPropertyName("element")] string? Element,
    [property: JsonPropertyName("action")] string? Action,
    [property: JsonPropertyName("type")] string? Type,
    [property: JsonPropertyName("cause")] string Cause);

public sealed record OpeErrorResponse(
    [property: JsonPropertyName("status_code")] int StatusCode,
    [property: JsonPropertyName("message")] string Message,
    [property: JsonPropertyName("typed_info")] OpeTypedInfo TypedInfo,
    [property: JsonPropertyName("data")] IReadOnlyDictionary<string, string>? Data);

public static class OpeMediaTypes
{
    public const string Version = "application/vnd.version+json";
    public const string Bookmarks = "application/vnd.bookmark-list+json";
    public const string GenericOperationRequest = "application/vnd.generic-operation-request+json";
    public const string GenericOperationResponse = "application/vnd.generic-operation-response+json";
    public const string Error = "application/vnd.generic-operation.error+json";
}

public static class OpeErrorCauses
{
    public const string WrongSignature = "WRONG_SIGNATURE";
    public const string FieldErrors = "FIELD_ERRORS";
    public const string ElementNotExists = "ELEMENT_NOT_EXISTS";
    public const string ConnectorError = "CONNECTOR_ERROR";
}

public static class OpeFieldErrors
{
    public const string Expected = "FIELD_EXPECTED";
    public const string NotExpected = "FIELD_NOT_EXPECTED";
    public const string UnexpectedFormat = "FIELD_UNEXPECTED_FORMAT";
}
