/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;

init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  
@endpointMap = {
    cn-hangzhou = 'cas.aliyuncs.com',
    ap-northeast-2-pop = 'cas.aliyuncs.com',
    ap-southeast-1 = 'cas.aliyuncs.com',
    ap-southeast-3 = 'cas.aliyuncs.com',
    ap-southeast-5 = 'cas.aliyuncs.com',
    cn-beijing = 'cas.aliyuncs.com',
    cn-beijing-finance-1 = 'cas.aliyuncs.com',
    cn-beijing-finance-pop = 'cas.aliyuncs.com',
    cn-beijing-gov-1 = 'cas.aliyuncs.com',
    cn-beijing-nu16-b01 = 'cas.aliyuncs.com',
    cn-chengdu = 'cas.aliyuncs.com',
    cn-edge-1 = 'cas.aliyuncs.com',
    cn-fujian = 'cas.aliyuncs.com',
    cn-haidian-cm12-c01 = 'cas.aliyuncs.com',
    cn-hangzhou-bj-b01 = 'cas.aliyuncs.com',
    cn-hangzhou-finance = 'cas.aliyuncs.com',
    cn-hangzhou-internal-prod-1 = 'cas.aliyuncs.com',
    cn-hangzhou-internal-test-1 = 'cas.aliyuncs.com',
    cn-hangzhou-internal-test-2 = 'cas.aliyuncs.com',
    cn-hangzhou-internal-test-3 = 'cas.aliyuncs.com',
    cn-hangzhou-test-306 = 'cas.aliyuncs.com',
    cn-hongkong = 'cas.aliyuncs.com',
    cn-hongkong-finance-pop = 'cas.aliyuncs.com',
    cn-huhehaote = 'cas.aliyuncs.com',
    cn-north-2-gov-1 = 'cas.aliyuncs.com',
    cn-qingdao = 'cas.aliyuncs.com',
    cn-qingdao-nebula = 'cas.aliyuncs.com',
    cn-shanghai = 'cas.aliyuncs.com',
    cn-shanghai-et15-b01 = 'cas.aliyuncs.com',
    cn-shanghai-et2-b01 = 'cas.aliyuncs.com',
    cn-shanghai-finance-1 = 'cas.aliyuncs.com',
    cn-shanghai-inner = 'cas.aliyuncs.com',
    cn-shanghai-internal-test-1 = 'cas.aliyuncs.com',
    cn-shenzhen = 'cas.aliyuncs.com',
    cn-shenzhen-finance-1 = 'cas.aliyuncs.com',
    cn-shenzhen-inner = 'cas.aliyuncs.com',
    cn-shenzhen-st4-d01 = 'cas.aliyuncs.com',
    cn-shenzhen-su18-b01 = 'cas.aliyuncs.com',
    cn-wuhan = 'cas.aliyuncs.com',
    cn-yushanfang = 'cas.aliyuncs.com',
    cn-zhangbei-na61-b01 = 'cas.aliyuncs.com',
    cn-zhangjiakou = 'cas.aliyuncs.com',
    cn-zhangjiakou-na62-a01 = 'cas.aliyuncs.com',
    cn-zhengzhou-nebula-1 = 'cas.aliyuncs.com',
    eu-west-1 = 'cas.aliyuncs.com',
    eu-west-1-oxs = 'cas.aliyuncs.com',
    rus-west-1-pop = 'cas.aliyuncs.com',
    us-east-1 = 'cas.aliyuncs.com',
    us-west-1 = 'cas.aliyuncs.com',
  };

  checkConfig(config);
  @endpoint = getEndpoint('cas', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }

  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}
model CancelCertificateForPackageRequestRequest {
  orderId?: long(name='OrderId'),
}

model CancelCertificateForPackageRequestResponseBody = {
  requestId?: string(name='RequestId'),
}

model CancelCertificateForPackageRequestResponse = {
  headers: map[string]string(name='headers'),
  body: CancelCertificateForPackageRequestResponseBody(name='body'),
}

async function cancelCertificateForPackageRequestWithOptions(request: CancelCertificateForPackageRequestRequest, runtime: Util.RuntimeOptions): CancelCertificateForPackageRequestResponse {
  Util.validateModel(request);
  var query = {};
  query["OrderId"] = request.orderId;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = Util.toMap(request),
  };
  var params = new OpenApi.Params{
    action = 'CancelCertificateForPackageRequest',
    version = '2020-04-07',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function cancelCertificateForPackageRequest(request: CancelCertificateForPackageRequestRequest): CancelCertificateForPackageRequestResponse {
  var runtime = new Util.RuntimeOptions{};
  return cancelCertificateForPackageRequestWithOptions(request, runtime);
}

model CancelOrderRequestRequest {
  orderId?: long(name='OrderId'),
}

model CancelOrderRequestResponseBody = {
  requestId?: string(name='RequestId'),
}

model CancelOrderRequestResponse = {
  headers: map[string]string(name='headers'),
  body: CancelOrderRequestResponseBody(name='body'),
}

async function cancelOrderRequestWithOptions(request: CancelOrderRequestRequest, runtime: Util.RuntimeOptions): CancelOrderRequestResponse {
  Util.validateModel(request);
  var query = {};
  query["OrderId"] = request.orderId;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = Util.toMap(request),
  };
  var params = new OpenApi.Params{
    action = 'CancelOrderRequest',
    version = '2020-04-07',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function cancelOrderRequest(request: CancelOrderRequestRequest): CancelOrderRequestResponse {
  var runtime = new Util.RuntimeOptions{};
  return cancelOrderRequestWithOptions(request, runtime);
}

model CreateCertificateForPackageRequestRequest {
  csr?: string(name='Csr'),
  productCode?: string(name='ProductCode'),
  username?: string(name='Username'),
  phone?: string(name='Phone'),
  email?: string(name='Email'),
  domain?: string(name='Domain'),
  companyName?: string(name='CompanyName'),
  validateType?: string(name='ValidateType'),
}

model CreateCertificateForPackageRequestResponseBody = {
  requestId?: string(name='RequestId'),
  orderId?: long(name='OrderId'),
}

model CreateCertificateForPackageRequestResponse = {
  headers: map[string]string(name='headers'),
  body: CreateCertificateForPackageRequestResponseBody(name='body'),
}

async function createCertificateForPackageRequestWithOptions(request: CreateCertificateForPackageRequestRequest, runtime: Util.RuntimeOptions): CreateCertificateForPackageRequestResponse {
  Util.validateModel(request);
  var query = {};
  query["Csr"] = request.csr;
  query["ProductCode"] = request.productCode;
  query["Username"] = request.username;
  query["Phone"] = request.phone;
  query["Email"] = request.email;
  query["Domain"] = request.domain;
  query["CompanyName"] = request.companyName;
  query["ValidateType"] = request.validateType;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = Util.toMap(request),
  };
  var params = new OpenApi.Params{
    action = 'CreateCertificateForPackageRequest',
    version = '2020-04-07',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function createCertificateForPackageRequest(request: CreateCertificateForPackageRequestRequest): CreateCertificateForPackageRequestResponse {
  var runtime = new Util.RuntimeOptions{};
  return createCertificateForPackageRequestWithOptions(request, runtime);
}

model CreateCertificateRequestRequest {
  productCode?: string(name='ProductCode'),
  username?: string(name='Username'),
  phone?: string(name='Phone'),
  email?: string(name='Email'),
  domain?: string(name='Domain'),
  validateType?: string(name='ValidateType'),
}

model CreateCertificateRequestResponseBody = {
  requestId?: string(name='RequestId'),
  orderId?: long(name='OrderId'),
}

model CreateCertificateRequestResponse = {
  headers: map[string]string(name='headers'),
  body: CreateCertificateRequestResponseBody(name='body'),
}

async function createCertificateRequestWithOptions(request: CreateCertificateRequestRequest, runtime: Util.RuntimeOptions): CreateCertificateRequestResponse {
  Util.validateModel(request);
  var query = {};
  query["ProductCode"] = request.productCode;
  query["Username"] = request.username;
  query["Phone"] = request.phone;
  query["Email"] = request.email;
  query["Domain"] = request.domain;
  query["ValidateType"] = request.validateType;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = Util.toMap(request),
  };
  var params = new OpenApi.Params{
    action = 'CreateCertificateRequest',
    version = '2020-04-07',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function createCertificateRequest(request: CreateCertificateRequestRequest): CreateCertificateRequestResponse {
  var runtime = new Util.RuntimeOptions{};
  return createCertificateRequestWithOptions(request, runtime);
}

model CreateCertificateWithCsrRequestRequest {
  csr?: string(name='Csr'),
  productCode?: string(name='ProductCode'),
  username?: string(name='Username'),
  phone?: string(name='Phone'),
  email?: string(name='Email'),
  validateType?: string(name='ValidateType'),
}

model CreateCertificateWithCsrRequestResponseBody = {
  requestId?: string(name='RequestId'),
  orderId?: long(name='OrderId'),
}

model CreateCertificateWithCsrRequestResponse = {
  headers: map[string]string(name='headers'),
  body: CreateCertificateWithCsrRequestResponseBody(name='body'),
}

async function createCertificateWithCsrRequestWithOptions(request: CreateCertificateWithCsrRequestRequest, runtime: Util.RuntimeOptions): CreateCertificateWithCsrRequestResponse {
  Util.validateModel(request);
  var query = {};
  query["Csr"] = request.csr;
  query["ProductCode"] = request.productCode;
  query["Username"] = request.username;
  query["Phone"] = request.phone;
  query["Email"] = request.email;
  query["ValidateType"] = request.validateType;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = Util.toMap(request),
  };
  var params = new OpenApi.Params{
    action = 'CreateCertificateWithCsrRequest',
    version = '2020-04-07',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function createCertificateWithCsrRequest(request: CreateCertificateWithCsrRequestRequest): CreateCertificateWithCsrRequestResponse {
  var runtime = new Util.RuntimeOptions{};
  return createCertificateWithCsrRequestWithOptions(request, runtime);
}

model DeleteCertificateRequestRequest {
  orderId?: long(name='OrderId'),
}

model DeleteCertificateRequestResponseBody = {
  requestId?: string(name='RequestId'),
}

model DeleteCertificateRequestResponse = {
  headers: map[string]string(name='headers'),
  body: DeleteCertificateRequestResponseBody(name='body'),
}

async function deleteCertificateRequestWithOptions(request: DeleteCertificateRequestRequest, runtime: Util.RuntimeOptions): DeleteCertificateRequestResponse {
  Util.validateModel(request);
  var query = {};
  query["OrderId"] = request.orderId;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = Util.toMap(request),
  };
  var params = new OpenApi.Params{
    action = 'DeleteCertificateRequest',
    version = '2020-04-07',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function deleteCertificateRequest(request: DeleteCertificateRequestRequest): DeleteCertificateRequestResponse {
  var runtime = new Util.RuntimeOptions{};
  return deleteCertificateRequestWithOptions(request, runtime);
}

model DescribeCertificateStateRequest {
  orderId?: long(name='OrderId'),
}

model DescribeCertificateStateResponseBody = {
  type?: string(name='Type'),
  privateKey?: string(name='PrivateKey'),
  recordType?: string(name='RecordType'),
  requestId?: string(name='RequestId'),
  content?: string(name='Content'),
  recordDomain?: string(name='RecordDomain'),
  recordValue?: string(name='RecordValue'),
  domain?: string(name='Domain'),
  validateType?: string(name='ValidateType'),
  uri?: string(name='Uri'),
  certificate?: string(name='Certificate'),
}

model DescribeCertificateStateResponse = {
  headers: map[string]string(name='headers'),
  body: DescribeCertificateStateResponseBody(name='body'),
}

async function describeCertificateStateWithOptions(request: DescribeCertificateStateRequest, runtime: Util.RuntimeOptions): DescribeCertificateStateResponse {
  Util.validateModel(request);
  var query = {};
  query["OrderId"] = request.orderId;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = Util.toMap(request),
  };
  var params = new OpenApi.Params{
    action = 'DescribeCertificateState',
    version = '2020-04-07',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function describeCertificateState(request: DescribeCertificateStateRequest): DescribeCertificateStateResponse {
  var runtime = new Util.RuntimeOptions{};
  return describeCertificateStateWithOptions(request, runtime);
}

model DescribePackageStateRequest {
  productCode?: string(name='ProductCode'),
}

model DescribePackageStateResponseBody = {
  totalCount?: long(name='TotalCount'),
  requestId?: string(name='RequestId'),
  productCode?: string(name='ProductCode'),
  usedCount?: long(name='UsedCount'),
  issuedCount?: long(name='IssuedCount'),
}

model DescribePackageStateResponse = {
  headers: map[string]string(name='headers'),
  body: DescribePackageStateResponseBody(name='body'),
}

async function describePackageStateWithOptions(request: DescribePackageStateRequest, runtime: Util.RuntimeOptions): DescribePackageStateResponse {
  Util.validateModel(request);
  var query = {};
  query["ProductCode"] = request.productCode;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = Util.toMap(request),
  };
  var params = new OpenApi.Params{
    action = 'DescribePackageState',
    version = '2020-04-07',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function describePackageState(request: DescribePackageStateRequest): DescribePackageStateResponse {
  var runtime = new Util.RuntimeOptions{};
  return describePackageStateWithOptions(request, runtime);
}

model RenewCertificateOrderForPackageRequestRequest {
  orderId?: long(name='OrderId'),
  csr?: string(name='Csr'),
}

model RenewCertificateOrderForPackageRequestResponseBody = {
  requestId?: string(name='RequestId'),
  orderId?: long(name='OrderId'),
}

model RenewCertificateOrderForPackageRequestResponse = {
  headers: map[string]string(name='headers'),
  body: RenewCertificateOrderForPackageRequestResponseBody(name='body'),
}

async function renewCertificateOrderForPackageRequestWithOptions(request: RenewCertificateOrderForPackageRequestRequest, runtime: Util.RuntimeOptions): RenewCertificateOrderForPackageRequestResponse {
  Util.validateModel(request);
  var query = {};
  query["OrderId"] = request.orderId;
  query["Csr"] = request.csr;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = Util.toMap(request),
  };
  var params = new OpenApi.Params{
    action = 'RenewCertificateOrderForPackageRequest',
    version = '2020-04-07',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function renewCertificateOrderForPackageRequest(request: RenewCertificateOrderForPackageRequestRequest): RenewCertificateOrderForPackageRequestResponse {
  var runtime = new Util.RuntimeOptions{};
  return renewCertificateOrderForPackageRequestWithOptions(request, runtime);
}

