// Generated by openapi-moonbit — DO NOT EDIT
// Spec SHA-256: 7e574664c0f434e52021e12f313a3266fd3175fe2ecddde4c0e0930549c72ba2

///|
#derive(Debug, Eq, Compare)
pub(all) enum HttpApiDeploymentScheme {
  /// Wire value: `http`.
  Http
  /// Wire value: `https`.
  Https
  /// Forward-compatible fallback for unrecognized wire values.
  Unknown(String)
}

///|
/// Wire string representation of `HttpApiDeploymentScheme`.
pub fn HttpApiDeploymentScheme::to_wire(
  self : HttpApiDeploymentScheme,
) -> String {
  match self {
    HttpApiDeploymentScheme::Http => "http"
    HttpApiDeploymentScheme::Https => "https"
    HttpApiDeploymentScheme::Unknown(raw) => raw
  }
}

///|
pub impl @cjson.FromJson for HttpApiDeploymentScheme with fn from_json(
  json : @cjson.Json,
  path : @cjson.DecodeContext,
) -> HttpApiDeploymentScheme raise @cjson.JsonDecodeError {
  let r = @rjson.JsonReader::new(json, path)
  match r.read_string() {
    "http" => HttpApiDeploymentScheme::Http
    "https" => HttpApiDeploymentScheme::Https
    other => HttpApiDeploymentScheme::Unknown(other)
  }
}

///|
pub impl @cjson.ToJson for HttpApiDeploymentScheme with fn to_json(
  self : HttpApiDeploymentScheme,
) -> @cjson.Json {
  @rjson.write_string(self.to_wire())
}

///|
pub extend HttpApiDeploymentScheme with @cjson.ToJson::{to_json}

///|
/// Header that can be used to provide the oidc session directly to the agent through http apis.
/// Failure to provide the header will result in a 401 response.
#derive(Debug, Eq, Compare)
pub(all) struct TestSessionHeaderAgentSecurity {
  /// wire: `headerName`.
  header_name : String
}

///|
pub impl @cjson.FromJson for TestSessionHeaderAgentSecurity with fn from_json(
  json : @cjson.Json,
  path : @cjson.DecodeContext,
) -> TestSessionHeaderAgentSecurity raise @cjson.JsonDecodeError {
  let __r = @rjson.JsonReader::new(json, path)
  let header_name = __r.req_field("headerName", __fr => __fr.read_string())
  { header_name, }
}

///|
pub impl @cjson.ToJson for TestSessionHeaderAgentSecurity with fn to_json(
  self : TestSessionHeaderAgentSecurity,
) -> @cjson.Json {
  let __obj = @rjson.ObjectBuilder::new()
  let _ = __obj.field("headerName", @rjson.write_string(self.header_name))
  __obj.build()
}

///|
pub extend TestSessionHeaderAgentSecurity with @cjson.ToJson::{to_json}

///|
/// OIDC security scheme in the environment that should be used for the agent.
/// If the requested security scheme does not exist in the environment, the route will be disabled at runtime.
#derive(Debug, Eq, Compare)
pub(all) struct SecuritySchemeAgentSecurity {
  /// wire: `securityScheme`.
  security_scheme : String
}

///|
pub impl @cjson.FromJson for SecuritySchemeAgentSecurity with fn from_json(
  json : @cjson.Json,
  path : @cjson.DecodeContext,
) -> SecuritySchemeAgentSecurity raise @cjson.JsonDecodeError {
  let __r = @rjson.JsonReader::new(json, path)
  let security_scheme = __r.req_field("securityScheme", __fr => {
    __fr.read_string()
  })
  { security_scheme, }
}

///|
pub impl @cjson.ToJson for SecuritySchemeAgentSecurity with fn to_json(
  self : SecuritySchemeAgentSecurity,
) -> @cjson.Json {
  let __obj = @rjson.ObjectBuilder::new()
  let _ = __obj.field(
    "securityScheme",
    @rjson.write_string(self.security_scheme),
  )
  __obj.build()
}

///|
pub extend SecuritySchemeAgentSecurity with @cjson.ToJson::{to_json}

///|
#derive(Debug, Eq, Compare)
pub(all) enum HttpApiDeploymentAgentSecurity {
  TestSessionHeader(TestSessionHeaderAgentSecurity)
  SecurityScheme(SecuritySchemeAgentSecurity)
}

///|
pub impl @cjson.FromJson for HttpApiDeploymentAgentSecurity with fn from_json(
  json : @cjson.Json,
  path : @cjson.DecodeContext,
) -> HttpApiDeploymentAgentSecurity raise @cjson.JsonDecodeError {
  let __r = @rjson.JsonReader::new(json, path)
  match __r.field("type").read_string() {
    "TestSessionHeader" =>
      HttpApiDeploymentAgentSecurity::TestSessionHeader(
        (
          @cjson.FromJson::from_json(__r.raw(), __r.context()) :
          TestSessionHeaderAgentSecurity),
      )
    "SecurityScheme" =>
      HttpApiDeploymentAgentSecurity::SecurityScheme(
        (
          @cjson.FromJson::from_json(__r.raw(), __r.context()) :
          SecuritySchemeAgentSecurity),
      )
    other => {
      let __err = __r.error(
        "unknown HttpApiDeploymentAgentSecurity tag: " + other,
      )
      raise __err
    }
  }
}

///|
pub impl @cjson.ToJson for HttpApiDeploymentAgentSecurity with fn to_json(
  self : HttpApiDeploymentAgentSecurity,
) -> @cjson.Json {
  match self {
    HttpApiDeploymentAgentSecurity::TestSessionHeader(__payload) =>
      @rjson.ObjectBuilder::new()
      .merge_object(__payload.to_json())
      .field("type", @rjson.write_string("TestSessionHeader"))
      .build()
    HttpApiDeploymentAgentSecurity::SecurityScheme(__payload) =>
      @rjson.ObjectBuilder::new()
      .merge_object(__payload.to_json())
      .field("type", @rjson.write_string("SecurityScheme"))
      .build()
  }
}

///|
pub extend HttpApiDeploymentAgentSecurity with @cjson.ToJson::{to_json}

///|
#derive(Debug, Eq, Compare)
pub(all) struct HttpApiDeploymentAgentOptions {
  /// Security option to use for all agent methods that require auth.
  /// Failure to provide a security option for an agent that requires one will lead to a deployment failure.
  security : HttpApiDeploymentAgentSecurity?
}

///|
/// Construct a `HttpApiDeploymentAgentOptions` with optional fields defaulting to absent/`None`.
pub fn HttpApiDeploymentAgentOptions::new(
  security? : HttpApiDeploymentAgentSecurity,
) -> HttpApiDeploymentAgentOptions {
  { security, }
}

///|
pub impl @cjson.FromJson for HttpApiDeploymentAgentOptions with fn from_json(
  json : @cjson.Json,
  path : @cjson.DecodeContext,
) -> HttpApiDeploymentAgentOptions raise @cjson.JsonDecodeError {
  let __r = @rjson.JsonReader::new(json, path)
  let security = __r.opt_field_as("security", __fr => {
    (
      @cjson.FromJson::from_json(__fr.raw(), __fr.context()) :
      HttpApiDeploymentAgentSecurity)
  })
  { security, }
}

///|
pub impl @cjson.ToJson for HttpApiDeploymentAgentOptions with fn to_json(
  self : HttpApiDeploymentAgentOptions,
) -> @cjson.Json {
  let __obj = @rjson.ObjectBuilder::new()
  let _ = __obj.opt_field(
    "security",
    match self.security {
      Option::Some(__fv) => Option::Some(__fv.to_json())
      Option::None => Option::None
    },
  )
  __obj.build()
}

///|
pub extend HttpApiDeploymentAgentOptions with @cjson.ToJson::{to_json}

///|
#derive(Debug, Eq)
pub(all) struct HttpApiDeployment {
  /// format: `uuid`.
  id : @uuid.UUID
  /// format: `uint64`.
  revision : UInt64
  /// format: `uuid`; wire: `environmentId`.
  environment_id : @uuid.UUID
  domain : String
  scheme : HttpApiDeploymentScheme
  /// format: `hash`.
  hash : String
  agents : Map[String, HttpApiDeploymentAgentOptions]
  /// wire: `webhooksPrefix`.
  webhooks_prefix : String
  /// wire: `openapiEndpointPrefix`.
  openapi_endpoint_prefix : String
  /// format: `date-time`; wire: `createdAt`.
  created_at : @rjson.DateTime
}

///|
pub impl @cjson.FromJson for HttpApiDeployment with fn from_json(
  json : @cjson.Json,
  path : @cjson.DecodeContext,
) -> HttpApiDeployment raise @cjson.JsonDecodeError {
  let __r = @rjson.JsonReader::new(json, path)
  let id = __r.req_field("id", __fr => {
    @uuid.from_hex(__fr.read_string()) catch {
      _ => {
        let __err = __fr.error("invalid uuid")
        raise __err
      }
    }
  })
  let revision = __r.req_field("revision", __fr => __fr.read_uint64())
  let environment_id = __r.req_field("environmentId", __fr => {
    @uuid.from_hex(__fr.read_string()) catch {
      _ => {
        let __err = __fr.error("invalid uuid")
        raise __err
      }
    }
  })
  let domain = __r.req_field("domain", __fr => __fr.read_string())
  let scheme = __r.req_field("scheme", __fr => {
    (
      @cjson.FromJson::from_json(__fr.raw(), __fr.context()) :
      HttpApiDeploymentScheme)
  })
  let hash = __r.req_field("hash", __fr => __fr.read_string())
  let agents = __r.req_field("agents", __fr => {
    __fr.read_map(__mv_0 => {
      (
        @cjson.FromJson::from_json(__mv_0.raw(), __mv_0.context()) :
        HttpApiDeploymentAgentOptions)
    })
  })
  let webhooks_prefix = __r.req_field("webhooksPrefix", __fr => {
    __fr.read_string()
  })
  let openapi_endpoint_prefix = __r.req_field("openapiEndpointPrefix", __fr => {
    __fr.read_string()
  })
  let created_at = __r.req_field("createdAt", __fr => {
    @rjson.DateTime::new(__fr.read_datetime())
  })
  {
    id,
    revision,
    environment_id,
    domain,
    scheme,
    hash,
    agents,
    webhooks_prefix,
    openapi_endpoint_prefix,
    created_at,
  }
}

///|
pub impl @cjson.ToJson for HttpApiDeployment with fn to_json(
  self : HttpApiDeployment,
) -> @cjson.Json {
  let __obj = @rjson.ObjectBuilder::new()
  let _ = __obj.field("id", @rjson.write_string(self.id.to_string()))
  let _ = __obj.field("revision", @rjson.write_uint64(self.revision))
  let _ = __obj.field(
    "environmentId",
    @rjson.write_string(self.environment_id.to_string()),
  )
  let _ = __obj.field("domain", @rjson.write_string(self.domain))
  let _ = __obj.field("scheme", self.scheme.to_json())
  let _ = __obj.field("hash", @rjson.write_string(self.hash))
  let _ = __obj.field(
    "agents",
    {
      let __mm_0 : Map[String, @cjson.Json] = Map([])
      for __mk_0, __mv_0 in self.agents {
        __mm_0[__mk_0] = __mv_0.to_json()
      }
      @cjson.Json::object(__mm_0)
    },
  )
  let _ = __obj.field(
    "webhooksPrefix",
    @rjson.write_string(self.webhooks_prefix),
  )
  let _ = __obj.field(
    "openapiEndpointPrefix",
    @rjson.write_string(self.openapi_endpoint_prefix),
  )
  let _ = __obj.field(
    "createdAt",
    @rjson.write_datetime(self.created_at.inner()),
  )
  __obj.build()
}

///|
pub extend HttpApiDeployment with @cjson.ToJson::{to_json}

///|
#derive(Debug, Eq)
pub(all) struct HttpApiDeploymentCreation {
  domain : String
  /// Public scheme advertised in OpenAPI. Does not configure the HTTP listener.
  ///
  /// default: `"https"`.
  scheme : HttpApiDeploymentScheme?
  /// wire: `webhooksPrefix`.
  webhooks_prefix : String
  /// wire: `openapiEndpointPrefix`.
  openapi_endpoint_prefix : String
  agents : Map[String, HttpApiDeploymentAgentOptions]
}

///|
/// Construct a `HttpApiDeploymentCreation` with optional fields defaulting to absent/`None`.
pub fn HttpApiDeploymentCreation::new(
  domain~ : String,
  webhooks_prefix~ : String,
  openapi_endpoint_prefix~ : String,
  agents~ : Map[String, HttpApiDeploymentAgentOptions],
  scheme? : HttpApiDeploymentScheme,
) -> HttpApiDeploymentCreation {
  { domain, scheme, webhooks_prefix, openapi_endpoint_prefix, agents, }
}

///|
pub impl @cjson.FromJson for HttpApiDeploymentCreation with fn from_json(
  json : @cjson.Json,
  path : @cjson.DecodeContext,
) -> HttpApiDeploymentCreation raise @cjson.JsonDecodeError {
  let __r = @rjson.JsonReader::new(json, path)
  let domain = __r.req_field("domain", __fr => __fr.read_string())
  let scheme = __r.opt_field_as("scheme", __fr => {
    (
      @cjson.FromJson::from_json(__fr.raw(), __fr.context()) :
      HttpApiDeploymentScheme)
  })
  let webhooks_prefix = __r.req_field("webhooksPrefix", __fr => {
    __fr.read_string()
  })
  let openapi_endpoint_prefix = __r.req_field("openapiEndpointPrefix", __fr => {
    __fr.read_string()
  })
  let agents = __r.req_field("agents", __fr => {
    __fr.read_map(__mv_0 => {
      (
        @cjson.FromJson::from_json(__mv_0.raw(), __mv_0.context()) :
        HttpApiDeploymentAgentOptions)
    })
  })
  { domain, scheme, webhooks_prefix, openapi_endpoint_prefix, agents, }
}

///|
pub impl @cjson.ToJson for HttpApiDeploymentCreation with fn to_json(
  self : HttpApiDeploymentCreation,
) -> @cjson.Json {
  let __obj = @rjson.ObjectBuilder::new()
  let _ = __obj.field("domain", @rjson.write_string(self.domain))
  let _ = __obj.opt_field(
    "scheme",
    match self.scheme {
      Option::Some(__fv) => Option::Some(__fv.to_json())
      Option::None => Option::None
    },
  )
  let _ = __obj.field(
    "webhooksPrefix",
    @rjson.write_string(self.webhooks_prefix),
  )
  let _ = __obj.field(
    "openapiEndpointPrefix",
    @rjson.write_string(self.openapi_endpoint_prefix),
  )
  let _ = __obj.field(
    "agents",
    {
      let __mm_0 : Map[String, @cjson.Json] = Map([])
      for __mk_0, __mv_0 in self.agents {
        __mm_0[__mk_0] = __mv_0.to_json()
      }
      @cjson.Json::object(__mm_0)
    },
  )
  __obj.build()
}

///|
pub extend HttpApiDeploymentCreation with @cjson.ToJson::{to_json}

///|
#derive(Debug, Eq)
pub(all) struct HttpApiDeploymentUpdate {
  /// format: `uint64`; wire: `currentRevision`.
  current_revision : UInt64
  scheme : HttpApiDeploymentScheme?
  /// wire: `webhookPrefix`.
  webhook_prefix : String?
  /// wire: `openapiEndpointPrefix`.
  openapi_endpoint_prefix : String?
  agents : Map[String, HttpApiDeploymentAgentOptions]?
}

///|
/// Construct a `HttpApiDeploymentUpdate` with optional fields defaulting to absent/`None`.
pub fn HttpApiDeploymentUpdate::new(
  current_revision~ : UInt64,
  scheme? : HttpApiDeploymentScheme,
  webhook_prefix? : String,
  openapi_endpoint_prefix? : String,
  agents? : Map[String, HttpApiDeploymentAgentOptions],
) -> HttpApiDeploymentUpdate {
  { current_revision, scheme, webhook_prefix, openapi_endpoint_prefix, agents, }
}

///|
pub impl @cjson.FromJson for HttpApiDeploymentUpdate with fn from_json(
  json : @cjson.Json,
  path : @cjson.DecodeContext,
) -> HttpApiDeploymentUpdate raise @cjson.JsonDecodeError {
  let __r = @rjson.JsonReader::new(json, path)
  let current_revision = __r.req_field("currentRevision", __fr => {
    __fr.read_uint64()
  })
  let scheme = __r.opt_field_as("scheme", __fr => {
    (
      @cjson.FromJson::from_json(__fr.raw(), __fr.context()) :
      HttpApiDeploymentScheme)
  })
  let webhook_prefix = __r.opt_field_as("webhookPrefix", __fr => {
    __fr.read_string()
  })
  let openapi_endpoint_prefix = __r.opt_field_as("openapiEndpointPrefix", __fr => {
    __fr.read_string()
  })
  let agents = __r.opt_field_as("agents", __fr => {
    __fr.read_map(__mv_0 => {
      (
        @cjson.FromJson::from_json(__mv_0.raw(), __mv_0.context()) :
        HttpApiDeploymentAgentOptions)
    })
  })
  { current_revision, scheme, webhook_prefix, openapi_endpoint_prefix, agents, }
}

///|
pub impl @cjson.ToJson for HttpApiDeploymentUpdate with fn to_json(
  self : HttpApiDeploymentUpdate,
) -> @cjson.Json {
  let __obj = @rjson.ObjectBuilder::new()
  let _ = __obj.field(
    "currentRevision",
    @rjson.write_uint64(self.current_revision),
  )
  let _ = __obj.opt_field(
    "scheme",
    match self.scheme {
      Option::Some(__fv) => Option::Some(__fv.to_json())
      Option::None => Option::None
    },
  )
  let _ = __obj.opt_field(
    "webhookPrefix",
    match self.webhook_prefix {
      Option::Some(__fv) => Option::Some(@rjson.write_string(__fv))
      Option::None => Option::None
    },
  )
  let _ = __obj.opt_field(
    "openapiEndpointPrefix",
    match self.openapi_endpoint_prefix {
      Option::Some(__fv) => Option::Some(@rjson.write_string(__fv))
      Option::None => Option::None
    },
  )
  let _ = __obj.opt_field(
    "agents",
    match self.agents {
      Option::Some(__fv) =>
        Option::Some(
          {
            let __mm_0 : Map[String, @cjson.Json] = Map([])
            for __mk_0, __mv_0 in __fv {
              __mm_0[__mk_0] = __mv_0.to_json()
            }
            @cjson.Json::object(__mm_0)
          },
        )
      Option::None => Option::None
    },
  )
  __obj.build()
}

///|
pub extend HttpApiDeploymentUpdate with @cjson.ToJson::{to_json}

///|
#derive(Debug, Eq)
pub(all) struct PageHttpApiDeployment {
  values : Array[HttpApiDeployment]
}

///|
pub impl @cjson.FromJson for PageHttpApiDeployment with fn from_json(
  json : @cjson.Json,
  path : @cjson.DecodeContext,
) -> PageHttpApiDeployment raise @cjson.JsonDecodeError {
  let __r = @rjson.JsonReader::new(json, path)
  let values = __r.req_field("values", __fr => {
    __fr
    .read_array()
    .map(__el_0 => {
      (
        @cjson.FromJson::from_json(__el_0.raw(), __el_0.context()) :
        HttpApiDeployment)
    })
  })
  { values, }
}

///|
pub impl @cjson.ToJson for PageHttpApiDeployment with fn to_json(
  self : PageHttpApiDeployment,
) -> @cjson.Json {
  let __obj = @rjson.ObjectBuilder::new()
  let _ = __obj.field(
    "values",
    @cjson.Json::array(self.values.map(__ev_0 => __ev_0.to_json())),
  )
  __obj.build()
}

///|
pub extend PageHttpApiDeployment with @cjson.ToJson::{to_json}