// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
//   protoc-gen-ts_proto  v2.11.6
//   protoc               v3.19.1
// source: workflows/workflows.proto

/* eslint-disable */
import { BinaryReader, BinaryWriter } from '@bufbuild/protobuf/wire';
import type { CallContext, CallOptions } from 'nice-grpc-common';
import { Timestamp } from '../google/protobuf/timestamp';
import { DesiredWorkerLabels, TriggerWorkflowRequest } from '../v1/shared/trigger';

export const protobufPackage = '';

export enum StickyStrategy {
  SOFT = 0,
  HARD = 1,
  UNRECOGNIZED = -1,
}

export function stickyStrategyFromJSON(object: any): StickyStrategy {
  switch (object) {
    case 0:
    case 'SOFT':
      return StickyStrategy.SOFT;
    case 1:
    case 'HARD':
      return StickyStrategy.HARD;
    case -1:
    case 'UNRECOGNIZED':
    default:
      return StickyStrategy.UNRECOGNIZED;
  }
}

export function stickyStrategyToJSON(object: StickyStrategy): string {
  switch (object) {
    case StickyStrategy.SOFT:
      return 'SOFT';
    case StickyStrategy.HARD:
      return 'HARD';
    case StickyStrategy.UNRECOGNIZED:
    default:
      return 'UNRECOGNIZED';
  }
}

export enum WorkflowKind {
  FUNCTION = 0,
  DURABLE = 1,
  DAG = 2,
  UNRECOGNIZED = -1,
}

export function workflowKindFromJSON(object: any): WorkflowKind {
  switch (object) {
    case 0:
    case 'FUNCTION':
      return WorkflowKind.FUNCTION;
    case 1:
    case 'DURABLE':
      return WorkflowKind.DURABLE;
    case 2:
    case 'DAG':
      return WorkflowKind.DAG;
    case -1:
    case 'UNRECOGNIZED':
    default:
      return WorkflowKind.UNRECOGNIZED;
  }
}

export function workflowKindToJSON(object: WorkflowKind): string {
  switch (object) {
    case WorkflowKind.FUNCTION:
      return 'FUNCTION';
    case WorkflowKind.DURABLE:
      return 'DURABLE';
    case WorkflowKind.DAG:
      return 'DAG';
    case WorkflowKind.UNRECOGNIZED:
    default:
      return 'UNRECOGNIZED';
  }
}

export enum ConcurrencyLimitStrategy {
  CANCEL_IN_PROGRESS = 0,
  /** DROP_NEWEST - deprecated */
  DROP_NEWEST = 1,
  /** QUEUE_NEWEST - deprecated */
  QUEUE_NEWEST = 2,
  GROUP_ROUND_ROBIN = 3,
  CANCEL_NEWEST = 4,
  UNRECOGNIZED = -1,
}

export function concurrencyLimitStrategyFromJSON(object: any): ConcurrencyLimitStrategy {
  switch (object) {
    case 0:
    case 'CANCEL_IN_PROGRESS':
      return ConcurrencyLimitStrategy.CANCEL_IN_PROGRESS;
    case 1:
    case 'DROP_NEWEST':
      return ConcurrencyLimitStrategy.DROP_NEWEST;
    case 2:
    case 'QUEUE_NEWEST':
      return ConcurrencyLimitStrategy.QUEUE_NEWEST;
    case 3:
    case 'GROUP_ROUND_ROBIN':
      return ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN;
    case 4:
    case 'CANCEL_NEWEST':
      return ConcurrencyLimitStrategy.CANCEL_NEWEST;
    case -1:
    case 'UNRECOGNIZED':
    default:
      return ConcurrencyLimitStrategy.UNRECOGNIZED;
  }
}

export function concurrencyLimitStrategyToJSON(object: ConcurrencyLimitStrategy): string {
  switch (object) {
    case ConcurrencyLimitStrategy.CANCEL_IN_PROGRESS:
      return 'CANCEL_IN_PROGRESS';
    case ConcurrencyLimitStrategy.DROP_NEWEST:
      return 'DROP_NEWEST';
    case ConcurrencyLimitStrategy.QUEUE_NEWEST:
      return 'QUEUE_NEWEST';
    case ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN:
      return 'GROUP_ROUND_ROBIN';
    case ConcurrencyLimitStrategy.CANCEL_NEWEST:
      return 'CANCEL_NEWEST';
    case ConcurrencyLimitStrategy.UNRECOGNIZED:
    default:
      return 'UNRECOGNIZED';
  }
}

export enum RateLimitDuration {
  SECOND = 0,
  MINUTE = 1,
  HOUR = 2,
  DAY = 3,
  WEEK = 4,
  MONTH = 5,
  YEAR = 6,
  UNRECOGNIZED = -1,
}

export function rateLimitDurationFromJSON(object: any): RateLimitDuration {
  switch (object) {
    case 0:
    case 'SECOND':
      return RateLimitDuration.SECOND;
    case 1:
    case 'MINUTE':
      return RateLimitDuration.MINUTE;
    case 2:
    case 'HOUR':
      return RateLimitDuration.HOUR;
    case 3:
    case 'DAY':
      return RateLimitDuration.DAY;
    case 4:
    case 'WEEK':
      return RateLimitDuration.WEEK;
    case 5:
    case 'MONTH':
      return RateLimitDuration.MONTH;
    case 6:
    case 'YEAR':
      return RateLimitDuration.YEAR;
    case -1:
    case 'UNRECOGNIZED':
    default:
      return RateLimitDuration.UNRECOGNIZED;
  }
}

export function rateLimitDurationToJSON(object: RateLimitDuration): string {
  switch (object) {
    case RateLimitDuration.SECOND:
      return 'SECOND';
    case RateLimitDuration.MINUTE:
      return 'MINUTE';
    case RateLimitDuration.HOUR:
      return 'HOUR';
    case RateLimitDuration.DAY:
      return 'DAY';
    case RateLimitDuration.WEEK:
      return 'WEEK';
    case RateLimitDuration.MONTH:
      return 'MONTH';
    case RateLimitDuration.YEAR:
      return 'YEAR';
    case RateLimitDuration.UNRECOGNIZED:
    default:
      return 'UNRECOGNIZED';
  }
}

export interface PutWorkflowRequest {
  opts: CreateWorkflowVersionOpts | undefined;
}

/** CreateWorkflowVersionOpts represents options to create a workflow version. */
export interface CreateWorkflowVersionOpts {
  /** (required) the workflow name */
  name: string;
  /** (optional) the workflow description */
  description: string;
  /** (required) the workflow version */
  version: string;
  /** (optional) event triggers for the workflow */
  eventTriggers: string[];
  /** (optional) cron triggers for the workflow */
  cronTriggers: string[];
  /** (optional) scheduled triggers for the workflow */
  scheduledTriggers: Date[];
  /** (required) the workflow jobs */
  jobs: CreateWorkflowJobOpts[];
  /** (optional) the workflow concurrency options */
  concurrency: WorkflowConcurrencyOpts | undefined;
  /** (optional) the timeout for the schedule */
  scheduleTimeout?: string | undefined;
  /** (optional) the input for the cron trigger */
  cronInput?: string | undefined;
  /** (optional) the job to run on failure */
  onFailureJob?: CreateWorkflowJobOpts | undefined;
  /** (optional) the sticky strategy for assigning tasks to workers */
  sticky?: StickyStrategy | undefined;
  /** (optional) the kind of workflow */
  kind?: WorkflowKind | undefined;
  /** (optional) the priority of the workflow */
  defaultPriority?: number | undefined;
}

export interface WorkflowConcurrencyOpts {
  /** (optional) the action id for getting the concurrency group */
  action?: string | undefined;
  /** (optional) the maximum number of concurrent workflow runs, default 1 */
  maxRuns?: number | undefined;
  /** (optional) the strategy to use when the concurrency limit is reached, default CANCEL_IN_PROGRESS */
  limitStrategy?: ConcurrencyLimitStrategy | undefined;
  /** (optional) the expression to use for concurrency */
  expression?: string | undefined;
}

/** CreateWorkflowJobOpts represents options to create a workflow job. */
export interface CreateWorkflowJobOpts {
  /** (required) the job name */
  name: string;
  /** (optional) the job description */
  description: string;
  /** (required) the job tasks */
  steps: CreateWorkflowStepOpts[];
}

/** CreateWorkflowStepOpts represents options to create a workflow task. */
export interface CreateWorkflowStepOpts {
  /** (required) the task name */
  readableId: string;
  /** (required) the task action id */
  action: string;
  /** (optional) the task timeout */
  timeout: string;
  /** (optional) the task inputs, assuming string representation of JSON */
  inputs: string;
  /** (optional) the task parents. if none are passed in, this is a root task */
  parents: string[];
  /** (optional) the custom task user data, assuming string representation of JSON */
  userData: string;
  /** (optional) the number of retries for the task, default 0 */
  retries: number;
  /** (optional) the rate limits for the task */
  rateLimits: CreateStepRateLimit[];
  /** (optional) the desired worker affinity state for the task */
  workerLabels: { [key: string]: DesiredWorkerLabels };
  /** (optional) the retry backoff factor for the task */
  backoffFactor?: number | undefined;
  /** (optional) the maximum backoff time for the task */
  backoffMaxSeconds?: number | undefined;
}

export interface CreateWorkflowStepOpts_WorkerLabelsEntry {
  key: string;
  value: DesiredWorkerLabels | undefined;
}

export interface CreateStepRateLimit {
  /** (required) the key for the rate limit */
  key: string;
  /** (optional) the number of units this task consumes */
  units?: number | undefined;
  /** (optional) a CEL expression for determining the rate limit key */
  keyExpr?: string | undefined;
  /** (optional) a CEL expression for determining the number of units consumed */
  unitsExpr?: string | undefined;
  /** (optional) a CEL expression for determining the total amount of rate limit units */
  limitValuesExpr?: string | undefined;
  /** (optional) the default rate limit window to use for dynamic rate limits */
  duration?: RateLimitDuration | undefined;
}

/** ListWorkflowsRequest is the request for ListWorkflows. */
export interface ListWorkflowsRequest {}

export interface ScheduleWorkflowRequest {
  name: string;
  schedules: Date[];
  /** (optional) the input data for the workflow */
  input: string;
  /** (optional) the parent workflow run id */
  parentId?: string | undefined;
  /** (optional) the parent task external run id */
  parentTaskRunExternalId?: string | undefined;
  /**
   * (optional) the index of the child workflow. if this is set, matches on the index or the
   * child key will be a no-op, even if the schedule has changed.
   */
  childIndex?: number | undefined;
  /**
   * (optional) the key for the child. if this is set, matches on the index or the
   * child key will be a no-op, even if the schedule has changed.
   */
  childKey?: string | undefined;
  /** (optional) the additional metadata for the workflow */
  additionalMetadata?: string | undefined;
  /** (optional) the priority of the workflow */
  priority?: number | undefined;
}

/** ScheduledWorkflow represents a scheduled workflow. */
export interface ScheduledWorkflow {
  id: string;
  triggerAt: Date | undefined;
}

/** WorkflowVersion represents the WorkflowVersion model. */
export interface WorkflowVersion {
  id: string;
  createdAt: Date | undefined;
  updatedAt: Date | undefined;
  version: string;
  order: number;
  workflowId: string;
  scheduledWorkflows: ScheduledWorkflow[];
}

/** WorkflowTriggerEventRef represents the WorkflowTriggerEventRef model. */
export interface WorkflowTriggerEventRef {
  parentId: string;
  eventKey: string;
}

/** WorkflowTriggerCronRef represents the WorkflowTriggerCronRef model. */
export interface WorkflowTriggerCronRef {
  parentId: string;
  cron: string;
}

export interface BulkTriggerWorkflowRequest {
  workflows: TriggerWorkflowRequest[];
}

export interface BulkTriggerWorkflowResponse {
  workflowRunIds: string[];
}

export interface TriggerWorkflowResponse {
  workflowRunId: string;
}

export interface PutRateLimitRequest {
  /** (required) the global key for the rate limit */
  key: string;
  /** (required) the max limit for the rate limit (per unit of time) */
  limit: number;
  /** (required) the duration of time for the rate limit (second|minute|hour) */
  duration: RateLimitDuration;
}

export interface PutRateLimitResponse {}

function createBasePutWorkflowRequest(): PutWorkflowRequest {
  return { opts: undefined };
}

export const PutWorkflowRequest: MessageFns<PutWorkflowRequest> = {
  encode(message: PutWorkflowRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.opts !== undefined) {
      CreateWorkflowVersionOpts.encode(message.opts, writer.uint32(10).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): PutWorkflowRequest {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBasePutWorkflowRequest();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.opts = CreateWorkflowVersionOpts.decode(reader, reader.uint32());
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): PutWorkflowRequest {
    return {
      opts: isSet(object.opts) ? CreateWorkflowVersionOpts.fromJSON(object.opts) : undefined,
    };
  },

  toJSON(message: PutWorkflowRequest): unknown {
    const obj: any = {};
    if (message.opts !== undefined) {
      obj.opts = CreateWorkflowVersionOpts.toJSON(message.opts);
    }
    return obj;
  },

  create(base?: DeepPartial<PutWorkflowRequest>): PutWorkflowRequest {
    return PutWorkflowRequest.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<PutWorkflowRequest>): PutWorkflowRequest {
    const message = createBasePutWorkflowRequest();
    message.opts =
      object.opts !== undefined && object.opts !== null
        ? CreateWorkflowVersionOpts.fromPartial(object.opts)
        : undefined;
    return message;
  },
};

function createBaseCreateWorkflowVersionOpts(): CreateWorkflowVersionOpts {
  return {
    name: '',
    description: '',
    version: '',
    eventTriggers: [],
    cronTriggers: [],
    scheduledTriggers: [],
    jobs: [],
    concurrency: undefined,
    scheduleTimeout: undefined,
    cronInput: undefined,
    onFailureJob: undefined,
    sticky: undefined,
    kind: undefined,
    defaultPriority: undefined,
  };
}

export const CreateWorkflowVersionOpts: MessageFns<CreateWorkflowVersionOpts> = {
  encode(
    message: CreateWorkflowVersionOpts,
    writer: BinaryWriter = new BinaryWriter()
  ): BinaryWriter {
    if (message.name !== '') {
      writer.uint32(10).string(message.name);
    }
    if (message.description !== '') {
      writer.uint32(18).string(message.description);
    }
    if (message.version !== '') {
      writer.uint32(26).string(message.version);
    }
    for (const v of message.eventTriggers) {
      writer.uint32(34).string(v!);
    }
    for (const v of message.cronTriggers) {
      writer.uint32(42).string(v!);
    }
    for (const v of message.scheduledTriggers) {
      Timestamp.encode(toTimestamp(v!), writer.uint32(50).fork()).join();
    }
    for (const v of message.jobs) {
      CreateWorkflowJobOpts.encode(v!, writer.uint32(58).fork()).join();
    }
    if (message.concurrency !== undefined) {
      WorkflowConcurrencyOpts.encode(message.concurrency, writer.uint32(66).fork()).join();
    }
    if (message.scheduleTimeout !== undefined) {
      writer.uint32(74).string(message.scheduleTimeout);
    }
    if (message.cronInput !== undefined) {
      writer.uint32(82).string(message.cronInput);
    }
    if (message.onFailureJob !== undefined) {
      CreateWorkflowJobOpts.encode(message.onFailureJob, writer.uint32(90).fork()).join();
    }
    if (message.sticky !== undefined) {
      writer.uint32(96).int32(message.sticky);
    }
    if (message.kind !== undefined) {
      writer.uint32(104).int32(message.kind);
    }
    if (message.defaultPriority !== undefined) {
      writer.uint32(112).int32(message.defaultPriority);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): CreateWorkflowVersionOpts {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseCreateWorkflowVersionOpts();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.name = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.description = reader.string();
          continue;
        }
        case 3: {
          if (tag !== 26) {
            break;
          }

          message.version = reader.string();
          continue;
        }
        case 4: {
          if (tag !== 34) {
            break;
          }

          message.eventTriggers.push(reader.string());
          continue;
        }
        case 5: {
          if (tag !== 42) {
            break;
          }

          message.cronTriggers.push(reader.string());
          continue;
        }
        case 6: {
          if (tag !== 50) {
            break;
          }

          message.scheduledTriggers.push(fromTimestamp(Timestamp.decode(reader, reader.uint32())));
          continue;
        }
        case 7: {
          if (tag !== 58) {
            break;
          }

          message.jobs.push(CreateWorkflowJobOpts.decode(reader, reader.uint32()));
          continue;
        }
        case 8: {
          if (tag !== 66) {
            break;
          }

          message.concurrency = WorkflowConcurrencyOpts.decode(reader, reader.uint32());
          continue;
        }
        case 9: {
          if (tag !== 74) {
            break;
          }

          message.scheduleTimeout = reader.string();
          continue;
        }
        case 10: {
          if (tag !== 82) {
            break;
          }

          message.cronInput = reader.string();
          continue;
        }
        case 11: {
          if (tag !== 90) {
            break;
          }

          message.onFailureJob = CreateWorkflowJobOpts.decode(reader, reader.uint32());
          continue;
        }
        case 12: {
          if (tag !== 96) {
            break;
          }

          message.sticky = reader.int32() as any;
          continue;
        }
        case 13: {
          if (tag !== 104) {
            break;
          }

          message.kind = reader.int32() as any;
          continue;
        }
        case 14: {
          if (tag !== 112) {
            break;
          }

          message.defaultPriority = reader.int32();
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): CreateWorkflowVersionOpts {
    return {
      name: isSet(object.name) ? globalThis.String(object.name) : '',
      description: isSet(object.description) ? globalThis.String(object.description) : '',
      version: isSet(object.version) ? globalThis.String(object.version) : '',
      eventTriggers: globalThis.Array.isArray(object?.eventTriggers)
        ? object.eventTriggers.map((e: any) => globalThis.String(e))
        : globalThis.Array.isArray(object?.event_triggers)
          ? object.event_triggers.map((e: any) => globalThis.String(e))
          : [],
      cronTriggers: globalThis.Array.isArray(object?.cronTriggers)
        ? object.cronTriggers.map((e: any) => globalThis.String(e))
        : globalThis.Array.isArray(object?.cron_triggers)
          ? object.cron_triggers.map((e: any) => globalThis.String(e))
          : [],
      scheduledTriggers: globalThis.Array.isArray(object?.scheduledTriggers)
        ? object.scheduledTriggers.map((e: any) => fromJsonTimestamp(e))
        : globalThis.Array.isArray(object?.scheduled_triggers)
          ? object.scheduled_triggers.map((e: any) => fromJsonTimestamp(e))
          : [],
      jobs: globalThis.Array.isArray(object?.jobs)
        ? object.jobs.map((e: any) => CreateWorkflowJobOpts.fromJSON(e))
        : [],
      concurrency: isSet(object.concurrency)
        ? WorkflowConcurrencyOpts.fromJSON(object.concurrency)
        : undefined,
      scheduleTimeout: isSet(object.scheduleTimeout)
        ? globalThis.String(object.scheduleTimeout)
        : isSet(object.schedule_timeout)
          ? globalThis.String(object.schedule_timeout)
          : undefined,
      cronInput: isSet(object.cronInput)
        ? globalThis.String(object.cronInput)
        : isSet(object.cron_input)
          ? globalThis.String(object.cron_input)
          : undefined,
      onFailureJob: isSet(object.onFailureJob)
        ? CreateWorkflowJobOpts.fromJSON(object.onFailureJob)
        : isSet(object.on_failure_job)
          ? CreateWorkflowJobOpts.fromJSON(object.on_failure_job)
          : undefined,
      sticky: isSet(object.sticky) ? stickyStrategyFromJSON(object.sticky) : undefined,
      kind: isSet(object.kind) ? workflowKindFromJSON(object.kind) : undefined,
      defaultPriority: isSet(object.defaultPriority)
        ? globalThis.Number(object.defaultPriority)
        : isSet(object.default_priority)
          ? globalThis.Number(object.default_priority)
          : undefined,
    };
  },

  toJSON(message: CreateWorkflowVersionOpts): unknown {
    const obj: any = {};
    if (message.name !== '') {
      obj.name = message.name;
    }
    if (message.description !== '') {
      obj.description = message.description;
    }
    if (message.version !== '') {
      obj.version = message.version;
    }
    if (message.eventTriggers?.length) {
      obj.eventTriggers = message.eventTriggers;
    }
    if (message.cronTriggers?.length) {
      obj.cronTriggers = message.cronTriggers;
    }
    if (message.scheduledTriggers?.length) {
      obj.scheduledTriggers = message.scheduledTriggers.map((e) => e.toISOString());
    }
    if (message.jobs?.length) {
      obj.jobs = message.jobs.map((e) => CreateWorkflowJobOpts.toJSON(e));
    }
    if (message.concurrency !== undefined) {
      obj.concurrency = WorkflowConcurrencyOpts.toJSON(message.concurrency);
    }
    if (message.scheduleTimeout !== undefined) {
      obj.scheduleTimeout = message.scheduleTimeout;
    }
    if (message.cronInput !== undefined) {
      obj.cronInput = message.cronInput;
    }
    if (message.onFailureJob !== undefined) {
      obj.onFailureJob = CreateWorkflowJobOpts.toJSON(message.onFailureJob);
    }
    if (message.sticky !== undefined) {
      obj.sticky = stickyStrategyToJSON(message.sticky);
    }
    if (message.kind !== undefined) {
      obj.kind = workflowKindToJSON(message.kind);
    }
    if (message.defaultPriority !== undefined) {
      obj.defaultPriority = Math.round(message.defaultPriority);
    }
    return obj;
  },

  create(base?: DeepPartial<CreateWorkflowVersionOpts>): CreateWorkflowVersionOpts {
    return CreateWorkflowVersionOpts.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<CreateWorkflowVersionOpts>): CreateWorkflowVersionOpts {
    const message = createBaseCreateWorkflowVersionOpts();
    message.name = object.name ?? '';
    message.description = object.description ?? '';
    message.version = object.version ?? '';
    message.eventTriggers = object.eventTriggers?.map((e) => e) || [];
    message.cronTriggers = object.cronTriggers?.map((e) => e) || [];
    message.scheduledTriggers = object.scheduledTriggers?.map((e) => e) || [];
    message.jobs = object.jobs?.map((e) => CreateWorkflowJobOpts.fromPartial(e)) || [];
    message.concurrency =
      object.concurrency !== undefined && object.concurrency !== null
        ? WorkflowConcurrencyOpts.fromPartial(object.concurrency)
        : undefined;
    message.scheduleTimeout = object.scheduleTimeout ?? undefined;
    message.cronInput = object.cronInput ?? undefined;
    message.onFailureJob =
      object.onFailureJob !== undefined && object.onFailureJob !== null
        ? CreateWorkflowJobOpts.fromPartial(object.onFailureJob)
        : undefined;
    message.sticky = object.sticky ?? undefined;
    message.kind = object.kind ?? undefined;
    message.defaultPriority = object.defaultPriority ?? undefined;
    return message;
  },
};

function createBaseWorkflowConcurrencyOpts(): WorkflowConcurrencyOpts {
  return { action: undefined, maxRuns: undefined, limitStrategy: undefined, expression: undefined };
}

export const WorkflowConcurrencyOpts: MessageFns<WorkflowConcurrencyOpts> = {
  encode(
    message: WorkflowConcurrencyOpts,
    writer: BinaryWriter = new BinaryWriter()
  ): BinaryWriter {
    if (message.action !== undefined) {
      writer.uint32(10).string(message.action);
    }
    if (message.maxRuns !== undefined) {
      writer.uint32(16).int32(message.maxRuns);
    }
    if (message.limitStrategy !== undefined) {
      writer.uint32(24).int32(message.limitStrategy);
    }
    if (message.expression !== undefined) {
      writer.uint32(34).string(message.expression);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): WorkflowConcurrencyOpts {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseWorkflowConcurrencyOpts();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.action = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 16) {
            break;
          }

          message.maxRuns = reader.int32();
          continue;
        }
        case 3: {
          if (tag !== 24) {
            break;
          }

          message.limitStrategy = reader.int32() as any;
          continue;
        }
        case 4: {
          if (tag !== 34) {
            break;
          }

          message.expression = reader.string();
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): WorkflowConcurrencyOpts {
    return {
      action: isSet(object.action) ? globalThis.String(object.action) : undefined,
      maxRuns: isSet(object.maxRuns)
        ? globalThis.Number(object.maxRuns)
        : isSet(object.max_runs)
          ? globalThis.Number(object.max_runs)
          : undefined,
      limitStrategy: isSet(object.limitStrategy)
        ? concurrencyLimitStrategyFromJSON(object.limitStrategy)
        : isSet(object.limit_strategy)
          ? concurrencyLimitStrategyFromJSON(object.limit_strategy)
          : undefined,
      expression: isSet(object.expression) ? globalThis.String(object.expression) : undefined,
    };
  },

  toJSON(message: WorkflowConcurrencyOpts): unknown {
    const obj: any = {};
    if (message.action !== undefined) {
      obj.action = message.action;
    }
    if (message.maxRuns !== undefined) {
      obj.maxRuns = Math.round(message.maxRuns);
    }
    if (message.limitStrategy !== undefined) {
      obj.limitStrategy = concurrencyLimitStrategyToJSON(message.limitStrategy);
    }
    if (message.expression !== undefined) {
      obj.expression = message.expression;
    }
    return obj;
  },

  create(base?: DeepPartial<WorkflowConcurrencyOpts>): WorkflowConcurrencyOpts {
    return WorkflowConcurrencyOpts.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<WorkflowConcurrencyOpts>): WorkflowConcurrencyOpts {
    const message = createBaseWorkflowConcurrencyOpts();
    message.action = object.action ?? undefined;
    message.maxRuns = object.maxRuns ?? undefined;
    message.limitStrategy = object.limitStrategy ?? undefined;
    message.expression = object.expression ?? undefined;
    return message;
  },
};

function createBaseCreateWorkflowJobOpts(): CreateWorkflowJobOpts {
  return { name: '', description: '', steps: [] };
}

export const CreateWorkflowJobOpts: MessageFns<CreateWorkflowJobOpts> = {
  encode(message: CreateWorkflowJobOpts, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.name !== '') {
      writer.uint32(10).string(message.name);
    }
    if (message.description !== '') {
      writer.uint32(18).string(message.description);
    }
    for (const v of message.steps) {
      CreateWorkflowStepOpts.encode(v!, writer.uint32(34).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): CreateWorkflowJobOpts {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseCreateWorkflowJobOpts();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.name = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.description = reader.string();
          continue;
        }
        case 4: {
          if (tag !== 34) {
            break;
          }

          message.steps.push(CreateWorkflowStepOpts.decode(reader, reader.uint32()));
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): CreateWorkflowJobOpts {
    return {
      name: isSet(object.name) ? globalThis.String(object.name) : '',
      description: isSet(object.description) ? globalThis.String(object.description) : '',
      steps: globalThis.Array.isArray(object?.steps)
        ? object.steps.map((e: any) => CreateWorkflowStepOpts.fromJSON(e))
        : [],
    };
  },

  toJSON(message: CreateWorkflowJobOpts): unknown {
    const obj: any = {};
    if (message.name !== '') {
      obj.name = message.name;
    }
    if (message.description !== '') {
      obj.description = message.description;
    }
    if (message.steps?.length) {
      obj.steps = message.steps.map((e) => CreateWorkflowStepOpts.toJSON(e));
    }
    return obj;
  },

  create(base?: DeepPartial<CreateWorkflowJobOpts>): CreateWorkflowJobOpts {
    return CreateWorkflowJobOpts.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<CreateWorkflowJobOpts>): CreateWorkflowJobOpts {
    const message = createBaseCreateWorkflowJobOpts();
    message.name = object.name ?? '';
    message.description = object.description ?? '';
    message.steps = object.steps?.map((e) => CreateWorkflowStepOpts.fromPartial(e)) || [];
    return message;
  },
};

function createBaseCreateWorkflowStepOpts(): CreateWorkflowStepOpts {
  return {
    readableId: '',
    action: '',
    timeout: '',
    inputs: '',
    parents: [],
    userData: '',
    retries: 0,
    rateLimits: [],
    workerLabels: {},
    backoffFactor: undefined,
    backoffMaxSeconds: undefined,
  };
}

export const CreateWorkflowStepOpts: MessageFns<CreateWorkflowStepOpts> = {
  encode(message: CreateWorkflowStepOpts, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.readableId !== '') {
      writer.uint32(10).string(message.readableId);
    }
    if (message.action !== '') {
      writer.uint32(18).string(message.action);
    }
    if (message.timeout !== '') {
      writer.uint32(26).string(message.timeout);
    }
    if (message.inputs !== '') {
      writer.uint32(34).string(message.inputs);
    }
    for (const v of message.parents) {
      writer.uint32(42).string(v!);
    }
    if (message.userData !== '') {
      writer.uint32(50).string(message.userData);
    }
    if (message.retries !== 0) {
      writer.uint32(56).int32(message.retries);
    }
    for (const v of message.rateLimits) {
      CreateStepRateLimit.encode(v!, writer.uint32(66).fork()).join();
    }
    globalThis.Object.entries(message.workerLabels).forEach(
      ([key, value]: [string, DesiredWorkerLabels]) => {
        CreateWorkflowStepOpts_WorkerLabelsEntry.encode(
          { key: key as any, value },
          writer.uint32(74).fork()
        ).join();
      }
    );
    if (message.backoffFactor !== undefined) {
      writer.uint32(85).float(message.backoffFactor);
    }
    if (message.backoffMaxSeconds !== undefined) {
      writer.uint32(88).int32(message.backoffMaxSeconds);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): CreateWorkflowStepOpts {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseCreateWorkflowStepOpts();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.readableId = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.action = reader.string();
          continue;
        }
        case 3: {
          if (tag !== 26) {
            break;
          }

          message.timeout = reader.string();
          continue;
        }
        case 4: {
          if (tag !== 34) {
            break;
          }

          message.inputs = reader.string();
          continue;
        }
        case 5: {
          if (tag !== 42) {
            break;
          }

          message.parents.push(reader.string());
          continue;
        }
        case 6: {
          if (tag !== 50) {
            break;
          }

          message.userData = reader.string();
          continue;
        }
        case 7: {
          if (tag !== 56) {
            break;
          }

          message.retries = reader.int32();
          continue;
        }
        case 8: {
          if (tag !== 66) {
            break;
          }

          message.rateLimits.push(CreateStepRateLimit.decode(reader, reader.uint32()));
          continue;
        }
        case 9: {
          if (tag !== 74) {
            break;
          }

          const entry9 = CreateWorkflowStepOpts_WorkerLabelsEntry.decode(reader, reader.uint32());
          if (entry9.value !== undefined) {
            message.workerLabels[entry9.key] = entry9.value;
          }
          continue;
        }
        case 10: {
          if (tag !== 85) {
            break;
          }

          message.backoffFactor = reader.float();
          continue;
        }
        case 11: {
          if (tag !== 88) {
            break;
          }

          message.backoffMaxSeconds = reader.int32();
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): CreateWorkflowStepOpts {
    return {
      readableId: isSet(object.readableId)
        ? globalThis.String(object.readableId)
        : isSet(object.readable_id)
          ? globalThis.String(object.readable_id)
          : '',
      action: isSet(object.action) ? globalThis.String(object.action) : '',
      timeout: isSet(object.timeout) ? globalThis.String(object.timeout) : '',
      inputs: isSet(object.inputs) ? globalThis.String(object.inputs) : '',
      parents: globalThis.Array.isArray(object?.parents)
        ? object.parents.map((e: any) => globalThis.String(e))
        : [],
      userData: isSet(object.userData)
        ? globalThis.String(object.userData)
        : isSet(object.user_data)
          ? globalThis.String(object.user_data)
          : '',
      retries: isSet(object.retries) ? globalThis.Number(object.retries) : 0,
      rateLimits: globalThis.Array.isArray(object?.rateLimits)
        ? object.rateLimits.map((e: any) => CreateStepRateLimit.fromJSON(e))
        : globalThis.Array.isArray(object?.rate_limits)
          ? object.rate_limits.map((e: any) => CreateStepRateLimit.fromJSON(e))
          : [],
      workerLabels: isObject(object.workerLabels)
        ? (globalThis.Object.entries(object.workerLabels) as [string, any][]).reduce(
            (acc: { [key: string]: DesiredWorkerLabels }, [key, value]: [string, any]) => {
              acc[key] = DesiredWorkerLabels.fromJSON(value);
              return acc;
            },
            {}
          )
        : isObject(object.worker_labels)
          ? (globalThis.Object.entries(object.worker_labels) as [string, any][]).reduce(
              (acc: { [key: string]: DesiredWorkerLabels }, [key, value]: [string, any]) => {
                acc[key] = DesiredWorkerLabels.fromJSON(value);
                return acc;
              },
              {}
            )
          : {},
      backoffFactor: isSet(object.backoffFactor)
        ? globalThis.Number(object.backoffFactor)
        : isSet(object.backoff_factor)
          ? globalThis.Number(object.backoff_factor)
          : undefined,
      backoffMaxSeconds: isSet(object.backoffMaxSeconds)
        ? globalThis.Number(object.backoffMaxSeconds)
        : isSet(object.backoff_max_seconds)
          ? globalThis.Number(object.backoff_max_seconds)
          : undefined,
    };
  },

  toJSON(message: CreateWorkflowStepOpts): unknown {
    const obj: any = {};
    if (message.readableId !== '') {
      obj.readableId = message.readableId;
    }
    if (message.action !== '') {
      obj.action = message.action;
    }
    if (message.timeout !== '') {
      obj.timeout = message.timeout;
    }
    if (message.inputs !== '') {
      obj.inputs = message.inputs;
    }
    if (message.parents?.length) {
      obj.parents = message.parents;
    }
    if (message.userData !== '') {
      obj.userData = message.userData;
    }
    if (message.retries !== 0) {
      obj.retries = Math.round(message.retries);
    }
    if (message.rateLimits?.length) {
      obj.rateLimits = message.rateLimits.map((e) => CreateStepRateLimit.toJSON(e));
    }
    if (message.workerLabels) {
      const entries = globalThis.Object.entries(message.workerLabels) as [
        string,
        DesiredWorkerLabels,
      ][];
      if (entries.length > 0) {
        obj.workerLabels = {};
        entries.forEach(([k, v]) => {
          obj.workerLabels[k] = DesiredWorkerLabels.toJSON(v);
        });
      }
    }
    if (message.backoffFactor !== undefined) {
      obj.backoffFactor = message.backoffFactor;
    }
    if (message.backoffMaxSeconds !== undefined) {
      obj.backoffMaxSeconds = Math.round(message.backoffMaxSeconds);
    }
    return obj;
  },

  create(base?: DeepPartial<CreateWorkflowStepOpts>): CreateWorkflowStepOpts {
    return CreateWorkflowStepOpts.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<CreateWorkflowStepOpts>): CreateWorkflowStepOpts {
    const message = createBaseCreateWorkflowStepOpts();
    message.readableId = object.readableId ?? '';
    message.action = object.action ?? '';
    message.timeout = object.timeout ?? '';
    message.inputs = object.inputs ?? '';
    message.parents = object.parents?.map((e) => e) || [];
    message.userData = object.userData ?? '';
    message.retries = object.retries ?? 0;
    message.rateLimits = object.rateLimits?.map((e) => CreateStepRateLimit.fromPartial(e)) || [];
    message.workerLabels = (
      globalThis.Object.entries(object.workerLabels ?? {}) as [string, DesiredWorkerLabels][]
    ).reduce(
      (
        acc: { [key: string]: DesiredWorkerLabels },
        [key, value]: [string, DesiredWorkerLabels]
      ) => {
        if (value !== undefined) {
          acc[key] = DesiredWorkerLabels.fromPartial(value);
        }
        return acc;
      },
      {}
    );
    message.backoffFactor = object.backoffFactor ?? undefined;
    message.backoffMaxSeconds = object.backoffMaxSeconds ?? undefined;
    return message;
  },
};

function createBaseCreateWorkflowStepOpts_WorkerLabelsEntry(): CreateWorkflowStepOpts_WorkerLabelsEntry {
  return { key: '', value: undefined };
}

export const CreateWorkflowStepOpts_WorkerLabelsEntry: MessageFns<CreateWorkflowStepOpts_WorkerLabelsEntry> =
  {
    encode(
      message: CreateWorkflowStepOpts_WorkerLabelsEntry,
      writer: BinaryWriter = new BinaryWriter()
    ): BinaryWriter {
      if (message.key !== '') {
        writer.uint32(10).string(message.key);
      }
      if (message.value !== undefined) {
        DesiredWorkerLabels.encode(message.value, writer.uint32(18).fork()).join();
      }
      return writer;
    },

    decode(
      input: BinaryReader | Uint8Array,
      length?: number
    ): CreateWorkflowStepOpts_WorkerLabelsEntry {
      const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
      const end = length === undefined ? reader.len : reader.pos + length;
      const message = createBaseCreateWorkflowStepOpts_WorkerLabelsEntry();
      while (reader.pos < end) {
        const tag = reader.uint32();
        switch (tag >>> 3) {
          case 1: {
            if (tag !== 10) {
              break;
            }

            message.key = reader.string();
            continue;
          }
          case 2: {
            if (tag !== 18) {
              break;
            }

            message.value = DesiredWorkerLabels.decode(reader, reader.uint32());
            continue;
          }
        }
        if ((tag & 7) === 4 || tag === 0) {
          break;
        }
        reader.skip(tag & 7);
      }
      return message;
    },

    fromJSON(object: any): CreateWorkflowStepOpts_WorkerLabelsEntry {
      return {
        key: isSet(object.key) ? globalThis.String(object.key) : '',
        value: isSet(object.value) ? DesiredWorkerLabels.fromJSON(object.value) : undefined,
      };
    },

    toJSON(message: CreateWorkflowStepOpts_WorkerLabelsEntry): unknown {
      const obj: any = {};
      if (message.key !== '') {
        obj.key = message.key;
      }
      if (message.value !== undefined) {
        obj.value = DesiredWorkerLabels.toJSON(message.value);
      }
      return obj;
    },

    create(
      base?: DeepPartial<CreateWorkflowStepOpts_WorkerLabelsEntry>
    ): CreateWorkflowStepOpts_WorkerLabelsEntry {
      return CreateWorkflowStepOpts_WorkerLabelsEntry.fromPartial(base ?? {});
    },
    fromPartial(
      object: DeepPartial<CreateWorkflowStepOpts_WorkerLabelsEntry>
    ): CreateWorkflowStepOpts_WorkerLabelsEntry {
      const message = createBaseCreateWorkflowStepOpts_WorkerLabelsEntry();
      message.key = object.key ?? '';
      message.value =
        object.value !== undefined && object.value !== null
          ? DesiredWorkerLabels.fromPartial(object.value)
          : undefined;
      return message;
    },
  };

function createBaseCreateStepRateLimit(): CreateStepRateLimit {
  return {
    key: '',
    units: undefined,
    keyExpr: undefined,
    unitsExpr: undefined,
    limitValuesExpr: undefined,
    duration: undefined,
  };
}

export const CreateStepRateLimit: MessageFns<CreateStepRateLimit> = {
  encode(message: CreateStepRateLimit, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.key !== '') {
      writer.uint32(10).string(message.key);
    }
    if (message.units !== undefined) {
      writer.uint32(16).int32(message.units);
    }
    if (message.keyExpr !== undefined) {
      writer.uint32(26).string(message.keyExpr);
    }
    if (message.unitsExpr !== undefined) {
      writer.uint32(34).string(message.unitsExpr);
    }
    if (message.limitValuesExpr !== undefined) {
      writer.uint32(42).string(message.limitValuesExpr);
    }
    if (message.duration !== undefined) {
      writer.uint32(48).int32(message.duration);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): CreateStepRateLimit {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseCreateStepRateLimit();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.key = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 16) {
            break;
          }

          message.units = reader.int32();
          continue;
        }
        case 3: {
          if (tag !== 26) {
            break;
          }

          message.keyExpr = reader.string();
          continue;
        }
        case 4: {
          if (tag !== 34) {
            break;
          }

          message.unitsExpr = reader.string();
          continue;
        }
        case 5: {
          if (tag !== 42) {
            break;
          }

          message.limitValuesExpr = reader.string();
          continue;
        }
        case 6: {
          if (tag !== 48) {
            break;
          }

          message.duration = reader.int32() as any;
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): CreateStepRateLimit {
    return {
      key: isSet(object.key) ? globalThis.String(object.key) : '',
      units: isSet(object.units) ? globalThis.Number(object.units) : undefined,
      keyExpr: isSet(object.keyExpr)
        ? globalThis.String(object.keyExpr)
        : isSet(object.key_expr)
          ? globalThis.String(object.key_expr)
          : undefined,
      unitsExpr: isSet(object.unitsExpr)
        ? globalThis.String(object.unitsExpr)
        : isSet(object.units_expr)
          ? globalThis.String(object.units_expr)
          : undefined,
      limitValuesExpr: isSet(object.limitValuesExpr)
        ? globalThis.String(object.limitValuesExpr)
        : isSet(object.limit_values_expr)
          ? globalThis.String(object.limit_values_expr)
          : undefined,
      duration: isSet(object.duration) ? rateLimitDurationFromJSON(object.duration) : undefined,
    };
  },

  toJSON(message: CreateStepRateLimit): unknown {
    const obj: any = {};
    if (message.key !== '') {
      obj.key = message.key;
    }
    if (message.units !== undefined) {
      obj.units = Math.round(message.units);
    }
    if (message.keyExpr !== undefined) {
      obj.keyExpr = message.keyExpr;
    }
    if (message.unitsExpr !== undefined) {
      obj.unitsExpr = message.unitsExpr;
    }
    if (message.limitValuesExpr !== undefined) {
      obj.limitValuesExpr = message.limitValuesExpr;
    }
    if (message.duration !== undefined) {
      obj.duration = rateLimitDurationToJSON(message.duration);
    }
    return obj;
  },

  create(base?: DeepPartial<CreateStepRateLimit>): CreateStepRateLimit {
    return CreateStepRateLimit.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<CreateStepRateLimit>): CreateStepRateLimit {
    const message = createBaseCreateStepRateLimit();
    message.key = object.key ?? '';
    message.units = object.units ?? undefined;
    message.keyExpr = object.keyExpr ?? undefined;
    message.unitsExpr = object.unitsExpr ?? undefined;
    message.limitValuesExpr = object.limitValuesExpr ?? undefined;
    message.duration = object.duration ?? undefined;
    return message;
  },
};

function createBaseListWorkflowsRequest(): ListWorkflowsRequest {
  return {};
}

export const ListWorkflowsRequest: MessageFns<ListWorkflowsRequest> = {
  encode(_: ListWorkflowsRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): ListWorkflowsRequest {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseListWorkflowsRequest();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(_: any): ListWorkflowsRequest {
    return {};
  },

  toJSON(_: ListWorkflowsRequest): unknown {
    const obj: any = {};
    return obj;
  },

  create(base?: DeepPartial<ListWorkflowsRequest>): ListWorkflowsRequest {
    return ListWorkflowsRequest.fromPartial(base ?? {});
  },
  fromPartial(_: DeepPartial<ListWorkflowsRequest>): ListWorkflowsRequest {
    const message = createBaseListWorkflowsRequest();
    return message;
  },
};

function createBaseScheduleWorkflowRequest(): ScheduleWorkflowRequest {
  return {
    name: '',
    schedules: [],
    input: '',
    parentId: undefined,
    parentTaskRunExternalId: undefined,
    childIndex: undefined,
    childKey: undefined,
    additionalMetadata: undefined,
    priority: undefined,
  };
}

export const ScheduleWorkflowRequest: MessageFns<ScheduleWorkflowRequest> = {
  encode(
    message: ScheduleWorkflowRequest,
    writer: BinaryWriter = new BinaryWriter()
  ): BinaryWriter {
    if (message.name !== '') {
      writer.uint32(10).string(message.name);
    }
    for (const v of message.schedules) {
      Timestamp.encode(toTimestamp(v!), writer.uint32(18).fork()).join();
    }
    if (message.input !== '') {
      writer.uint32(26).string(message.input);
    }
    if (message.parentId !== undefined) {
      writer.uint32(34).string(message.parentId);
    }
    if (message.parentTaskRunExternalId !== undefined) {
      writer.uint32(42).string(message.parentTaskRunExternalId);
    }
    if (message.childIndex !== undefined) {
      writer.uint32(48).int32(message.childIndex);
    }
    if (message.childKey !== undefined) {
      writer.uint32(58).string(message.childKey);
    }
    if (message.additionalMetadata !== undefined) {
      writer.uint32(66).string(message.additionalMetadata);
    }
    if (message.priority !== undefined) {
      writer.uint32(72).int32(message.priority);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): ScheduleWorkflowRequest {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseScheduleWorkflowRequest();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.name = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.schedules.push(fromTimestamp(Timestamp.decode(reader, reader.uint32())));
          continue;
        }
        case 3: {
          if (tag !== 26) {
            break;
          }

          message.input = reader.string();
          continue;
        }
        case 4: {
          if (tag !== 34) {
            break;
          }

          message.parentId = reader.string();
          continue;
        }
        case 5: {
          if (tag !== 42) {
            break;
          }

          message.parentTaskRunExternalId = reader.string();
          continue;
        }
        case 6: {
          if (tag !== 48) {
            break;
          }

          message.childIndex = reader.int32();
          continue;
        }
        case 7: {
          if (tag !== 58) {
            break;
          }

          message.childKey = reader.string();
          continue;
        }
        case 8: {
          if (tag !== 66) {
            break;
          }

          message.additionalMetadata = reader.string();
          continue;
        }
        case 9: {
          if (tag !== 72) {
            break;
          }

          message.priority = reader.int32();
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): ScheduleWorkflowRequest {
    return {
      name: isSet(object.name) ? globalThis.String(object.name) : '',
      schedules: globalThis.Array.isArray(object?.schedules)
        ? object.schedules.map((e: any) => fromJsonTimestamp(e))
        : [],
      input: isSet(object.input) ? globalThis.String(object.input) : '',
      parentId: isSet(object.parentId)
        ? globalThis.String(object.parentId)
        : isSet(object.parent_id)
          ? globalThis.String(object.parent_id)
          : undefined,
      parentTaskRunExternalId: isSet(object.parentTaskRunExternalId)
        ? globalThis.String(object.parentTaskRunExternalId)
        : isSet(object.parent_task_run_external_id)
          ? globalThis.String(object.parent_task_run_external_id)
          : undefined,
      childIndex: isSet(object.childIndex)
        ? globalThis.Number(object.childIndex)
        : isSet(object.child_index)
          ? globalThis.Number(object.child_index)
          : undefined,
      childKey: isSet(object.childKey)
        ? globalThis.String(object.childKey)
        : isSet(object.child_key)
          ? globalThis.String(object.child_key)
          : undefined,
      additionalMetadata: isSet(object.additionalMetadata)
        ? globalThis.String(object.additionalMetadata)
        : isSet(object.additional_metadata)
          ? globalThis.String(object.additional_metadata)
          : undefined,
      priority: isSet(object.priority) ? globalThis.Number(object.priority) : undefined,
    };
  },

  toJSON(message: ScheduleWorkflowRequest): unknown {
    const obj: any = {};
    if (message.name !== '') {
      obj.name = message.name;
    }
    if (message.schedules?.length) {
      obj.schedules = message.schedules.map((e) => e.toISOString());
    }
    if (message.input !== '') {
      obj.input = message.input;
    }
    if (message.parentId !== undefined) {
      obj.parentId = message.parentId;
    }
    if (message.parentTaskRunExternalId !== undefined) {
      obj.parentTaskRunExternalId = message.parentTaskRunExternalId;
    }
    if (message.childIndex !== undefined) {
      obj.childIndex = Math.round(message.childIndex);
    }
    if (message.childKey !== undefined) {
      obj.childKey = message.childKey;
    }
    if (message.additionalMetadata !== undefined) {
      obj.additionalMetadata = message.additionalMetadata;
    }
    if (message.priority !== undefined) {
      obj.priority = Math.round(message.priority);
    }
    return obj;
  },

  create(base?: DeepPartial<ScheduleWorkflowRequest>): ScheduleWorkflowRequest {
    return ScheduleWorkflowRequest.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<ScheduleWorkflowRequest>): ScheduleWorkflowRequest {
    const message = createBaseScheduleWorkflowRequest();
    message.name = object.name ?? '';
    message.schedules = object.schedules?.map((e) => e) || [];
    message.input = object.input ?? '';
    message.parentId = object.parentId ?? undefined;
    message.parentTaskRunExternalId = object.parentTaskRunExternalId ?? undefined;
    message.childIndex = object.childIndex ?? undefined;
    message.childKey = object.childKey ?? undefined;
    message.additionalMetadata = object.additionalMetadata ?? undefined;
    message.priority = object.priority ?? undefined;
    return message;
  },
};

function createBaseScheduledWorkflow(): ScheduledWorkflow {
  return { id: '', triggerAt: undefined };
}

export const ScheduledWorkflow: MessageFns<ScheduledWorkflow> = {
  encode(message: ScheduledWorkflow, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.id !== '') {
      writer.uint32(10).string(message.id);
    }
    if (message.triggerAt !== undefined) {
      Timestamp.encode(toTimestamp(message.triggerAt), writer.uint32(18).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): ScheduledWorkflow {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseScheduledWorkflow();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.id = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.triggerAt = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): ScheduledWorkflow {
    return {
      id: isSet(object.id) ? globalThis.String(object.id) : '',
      triggerAt: isSet(object.triggerAt)
        ? fromJsonTimestamp(object.triggerAt)
        : isSet(object.trigger_at)
          ? fromJsonTimestamp(object.trigger_at)
          : undefined,
    };
  },

  toJSON(message: ScheduledWorkflow): unknown {
    const obj: any = {};
    if (message.id !== '') {
      obj.id = message.id;
    }
    if (message.triggerAt !== undefined) {
      obj.triggerAt = message.triggerAt.toISOString();
    }
    return obj;
  },

  create(base?: DeepPartial<ScheduledWorkflow>): ScheduledWorkflow {
    return ScheduledWorkflow.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<ScheduledWorkflow>): ScheduledWorkflow {
    const message = createBaseScheduledWorkflow();
    message.id = object.id ?? '';
    message.triggerAt = object.triggerAt ?? undefined;
    return message;
  },
};

function createBaseWorkflowVersion(): WorkflowVersion {
  return {
    id: '',
    createdAt: undefined,
    updatedAt: undefined,
    version: '',
    order: 0,
    workflowId: '',
    scheduledWorkflows: [],
  };
}

export const WorkflowVersion: MessageFns<WorkflowVersion> = {
  encode(message: WorkflowVersion, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.id !== '') {
      writer.uint32(10).string(message.id);
    }
    if (message.createdAt !== undefined) {
      Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(18).fork()).join();
    }
    if (message.updatedAt !== undefined) {
      Timestamp.encode(toTimestamp(message.updatedAt), writer.uint32(26).fork()).join();
    }
    if (message.version !== '') {
      writer.uint32(42).string(message.version);
    }
    if (message.order !== 0) {
      writer.uint32(48).int64(message.order);
    }
    if (message.workflowId !== '') {
      writer.uint32(58).string(message.workflowId);
    }
    for (const v of message.scheduledWorkflows) {
      ScheduledWorkflow.encode(v!, writer.uint32(66).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): WorkflowVersion {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseWorkflowVersion();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.id = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.createdAt = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
          continue;
        }
        case 3: {
          if (tag !== 26) {
            break;
          }

          message.updatedAt = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
          continue;
        }
        case 5: {
          if (tag !== 42) {
            break;
          }

          message.version = reader.string();
          continue;
        }
        case 6: {
          if (tag !== 48) {
            break;
          }

          message.order = longToNumber(reader.int64());
          continue;
        }
        case 7: {
          if (tag !== 58) {
            break;
          }

          message.workflowId = reader.string();
          continue;
        }
        case 8: {
          if (tag !== 66) {
            break;
          }

          message.scheduledWorkflows.push(ScheduledWorkflow.decode(reader, reader.uint32()));
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): WorkflowVersion {
    return {
      id: isSet(object.id) ? globalThis.String(object.id) : '',
      createdAt: isSet(object.createdAt)
        ? fromJsonTimestamp(object.createdAt)
        : isSet(object.created_at)
          ? fromJsonTimestamp(object.created_at)
          : undefined,
      updatedAt: isSet(object.updatedAt)
        ? fromJsonTimestamp(object.updatedAt)
        : isSet(object.updated_at)
          ? fromJsonTimestamp(object.updated_at)
          : undefined,
      version: isSet(object.version) ? globalThis.String(object.version) : '',
      order: isSet(object.order) ? globalThis.Number(object.order) : 0,
      workflowId: isSet(object.workflowId)
        ? globalThis.String(object.workflowId)
        : isSet(object.workflow_id)
          ? globalThis.String(object.workflow_id)
          : '',
      scheduledWorkflows: globalThis.Array.isArray(object?.scheduledWorkflows)
        ? object.scheduledWorkflows.map((e: any) => ScheduledWorkflow.fromJSON(e))
        : globalThis.Array.isArray(object?.scheduled_workflows)
          ? object.scheduled_workflows.map((e: any) => ScheduledWorkflow.fromJSON(e))
          : [],
    };
  },

  toJSON(message: WorkflowVersion): unknown {
    const obj: any = {};
    if (message.id !== '') {
      obj.id = message.id;
    }
    if (message.createdAt !== undefined) {
      obj.createdAt = message.createdAt.toISOString();
    }
    if (message.updatedAt !== undefined) {
      obj.updatedAt = message.updatedAt.toISOString();
    }
    if (message.version !== '') {
      obj.version = message.version;
    }
    if (message.order !== 0) {
      obj.order = Math.round(message.order);
    }
    if (message.workflowId !== '') {
      obj.workflowId = message.workflowId;
    }
    if (message.scheduledWorkflows?.length) {
      obj.scheduledWorkflows = message.scheduledWorkflows.map((e) => ScheduledWorkflow.toJSON(e));
    }
    return obj;
  },

  create(base?: DeepPartial<WorkflowVersion>): WorkflowVersion {
    return WorkflowVersion.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<WorkflowVersion>): WorkflowVersion {
    const message = createBaseWorkflowVersion();
    message.id = object.id ?? '';
    message.createdAt = object.createdAt ?? undefined;
    message.updatedAt = object.updatedAt ?? undefined;
    message.version = object.version ?? '';
    message.order = object.order ?? 0;
    message.workflowId = object.workflowId ?? '';
    message.scheduledWorkflows =
      object.scheduledWorkflows?.map((e) => ScheduledWorkflow.fromPartial(e)) || [];
    return message;
  },
};

function createBaseWorkflowTriggerEventRef(): WorkflowTriggerEventRef {
  return { parentId: '', eventKey: '' };
}

export const WorkflowTriggerEventRef: MessageFns<WorkflowTriggerEventRef> = {
  encode(
    message: WorkflowTriggerEventRef,
    writer: BinaryWriter = new BinaryWriter()
  ): BinaryWriter {
    if (message.parentId !== '') {
      writer.uint32(10).string(message.parentId);
    }
    if (message.eventKey !== '') {
      writer.uint32(18).string(message.eventKey);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): WorkflowTriggerEventRef {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseWorkflowTriggerEventRef();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.parentId = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.eventKey = reader.string();
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): WorkflowTriggerEventRef {
    return {
      parentId: isSet(object.parentId)
        ? globalThis.String(object.parentId)
        : isSet(object.parent_id)
          ? globalThis.String(object.parent_id)
          : '',
      eventKey: isSet(object.eventKey)
        ? globalThis.String(object.eventKey)
        : isSet(object.event_key)
          ? globalThis.String(object.event_key)
          : '',
    };
  },

  toJSON(message: WorkflowTriggerEventRef): unknown {
    const obj: any = {};
    if (message.parentId !== '') {
      obj.parentId = message.parentId;
    }
    if (message.eventKey !== '') {
      obj.eventKey = message.eventKey;
    }
    return obj;
  },

  create(base?: DeepPartial<WorkflowTriggerEventRef>): WorkflowTriggerEventRef {
    return WorkflowTriggerEventRef.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<WorkflowTriggerEventRef>): WorkflowTriggerEventRef {
    const message = createBaseWorkflowTriggerEventRef();
    message.parentId = object.parentId ?? '';
    message.eventKey = object.eventKey ?? '';
    return message;
  },
};

function createBaseWorkflowTriggerCronRef(): WorkflowTriggerCronRef {
  return { parentId: '', cron: '' };
}

export const WorkflowTriggerCronRef: MessageFns<WorkflowTriggerCronRef> = {
  encode(message: WorkflowTriggerCronRef, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.parentId !== '') {
      writer.uint32(10).string(message.parentId);
    }
    if (message.cron !== '') {
      writer.uint32(18).string(message.cron);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): WorkflowTriggerCronRef {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseWorkflowTriggerCronRef();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.parentId = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.cron = reader.string();
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): WorkflowTriggerCronRef {
    return {
      parentId: isSet(object.parentId)
        ? globalThis.String(object.parentId)
        : isSet(object.parent_id)
          ? globalThis.String(object.parent_id)
          : '',
      cron: isSet(object.cron) ? globalThis.String(object.cron) : '',
    };
  },

  toJSON(message: WorkflowTriggerCronRef): unknown {
    const obj: any = {};
    if (message.parentId !== '') {
      obj.parentId = message.parentId;
    }
    if (message.cron !== '') {
      obj.cron = message.cron;
    }
    return obj;
  },

  create(base?: DeepPartial<WorkflowTriggerCronRef>): WorkflowTriggerCronRef {
    return WorkflowTriggerCronRef.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<WorkflowTriggerCronRef>): WorkflowTriggerCronRef {
    const message = createBaseWorkflowTriggerCronRef();
    message.parentId = object.parentId ?? '';
    message.cron = object.cron ?? '';
    return message;
  },
};

function createBaseBulkTriggerWorkflowRequest(): BulkTriggerWorkflowRequest {
  return { workflows: [] };
}

export const BulkTriggerWorkflowRequest: MessageFns<BulkTriggerWorkflowRequest> = {
  encode(
    message: BulkTriggerWorkflowRequest,
    writer: BinaryWriter = new BinaryWriter()
  ): BinaryWriter {
    for (const v of message.workflows) {
      TriggerWorkflowRequest.encode(v!, writer.uint32(10).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): BulkTriggerWorkflowRequest {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseBulkTriggerWorkflowRequest();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.workflows.push(TriggerWorkflowRequest.decode(reader, reader.uint32()));
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): BulkTriggerWorkflowRequest {
    return {
      workflows: globalThis.Array.isArray(object?.workflows)
        ? object.workflows.map((e: any) => TriggerWorkflowRequest.fromJSON(e))
        : [],
    };
  },

  toJSON(message: BulkTriggerWorkflowRequest): unknown {
    const obj: any = {};
    if (message.workflows?.length) {
      obj.workflows = message.workflows.map((e) => TriggerWorkflowRequest.toJSON(e));
    }
    return obj;
  },

  create(base?: DeepPartial<BulkTriggerWorkflowRequest>): BulkTriggerWorkflowRequest {
    return BulkTriggerWorkflowRequest.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<BulkTriggerWorkflowRequest>): BulkTriggerWorkflowRequest {
    const message = createBaseBulkTriggerWorkflowRequest();
    message.workflows = object.workflows?.map((e) => TriggerWorkflowRequest.fromPartial(e)) || [];
    return message;
  },
};

function createBaseBulkTriggerWorkflowResponse(): BulkTriggerWorkflowResponse {
  return { workflowRunIds: [] };
}

export const BulkTriggerWorkflowResponse: MessageFns<BulkTriggerWorkflowResponse> = {
  encode(
    message: BulkTriggerWorkflowResponse,
    writer: BinaryWriter = new BinaryWriter()
  ): BinaryWriter {
    for (const v of message.workflowRunIds) {
      writer.uint32(10).string(v!);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): BulkTriggerWorkflowResponse {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseBulkTriggerWorkflowResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.workflowRunIds.push(reader.string());
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): BulkTriggerWorkflowResponse {
    return {
      workflowRunIds: globalThis.Array.isArray(object?.workflowRunIds)
        ? object.workflowRunIds.map((e: any) => globalThis.String(e))
        : globalThis.Array.isArray(object?.workflow_run_ids)
          ? object.workflow_run_ids.map((e: any) => globalThis.String(e))
          : [],
    };
  },

  toJSON(message: BulkTriggerWorkflowResponse): unknown {
    const obj: any = {};
    if (message.workflowRunIds?.length) {
      obj.workflowRunIds = message.workflowRunIds;
    }
    return obj;
  },

  create(base?: DeepPartial<BulkTriggerWorkflowResponse>): BulkTriggerWorkflowResponse {
    return BulkTriggerWorkflowResponse.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<BulkTriggerWorkflowResponse>): BulkTriggerWorkflowResponse {
    const message = createBaseBulkTriggerWorkflowResponse();
    message.workflowRunIds = object.workflowRunIds?.map((e) => e) || [];
    return message;
  },
};

function createBaseTriggerWorkflowResponse(): TriggerWorkflowResponse {
  return { workflowRunId: '' };
}

export const TriggerWorkflowResponse: MessageFns<TriggerWorkflowResponse> = {
  encode(
    message: TriggerWorkflowResponse,
    writer: BinaryWriter = new BinaryWriter()
  ): BinaryWriter {
    if (message.workflowRunId !== '') {
      writer.uint32(10).string(message.workflowRunId);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): TriggerWorkflowResponse {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseTriggerWorkflowResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.workflowRunId = reader.string();
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): TriggerWorkflowResponse {
    return {
      workflowRunId: isSet(object.workflowRunId)
        ? globalThis.String(object.workflowRunId)
        : isSet(object.workflow_run_id)
          ? globalThis.String(object.workflow_run_id)
          : '',
    };
  },

  toJSON(message: TriggerWorkflowResponse): unknown {
    const obj: any = {};
    if (message.workflowRunId !== '') {
      obj.workflowRunId = message.workflowRunId;
    }
    return obj;
  },

  create(base?: DeepPartial<TriggerWorkflowResponse>): TriggerWorkflowResponse {
    return TriggerWorkflowResponse.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<TriggerWorkflowResponse>): TriggerWorkflowResponse {
    const message = createBaseTriggerWorkflowResponse();
    message.workflowRunId = object.workflowRunId ?? '';
    return message;
  },
};

function createBasePutRateLimitRequest(): PutRateLimitRequest {
  return { key: '', limit: 0, duration: 0 };
}

export const PutRateLimitRequest: MessageFns<PutRateLimitRequest> = {
  encode(message: PutRateLimitRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.key !== '') {
      writer.uint32(10).string(message.key);
    }
    if (message.limit !== 0) {
      writer.uint32(16).int32(message.limit);
    }
    if (message.duration !== 0) {
      writer.uint32(24).int32(message.duration);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): PutRateLimitRequest {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBasePutRateLimitRequest();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1: {
          if (tag !== 10) {
            break;
          }

          message.key = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 16) {
            break;
          }

          message.limit = reader.int32();
          continue;
        }
        case 3: {
          if (tag !== 24) {
            break;
          }

          message.duration = reader.int32() as any;
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): PutRateLimitRequest {
    return {
      key: isSet(object.key) ? globalThis.String(object.key) : '',
      limit: isSet(object.limit) ? globalThis.Number(object.limit) : 0,
      duration: isSet(object.duration) ? rateLimitDurationFromJSON(object.duration) : 0,
    };
  },

  toJSON(message: PutRateLimitRequest): unknown {
    const obj: any = {};
    if (message.key !== '') {
      obj.key = message.key;
    }
    if (message.limit !== 0) {
      obj.limit = Math.round(message.limit);
    }
    if (message.duration !== 0) {
      obj.duration = rateLimitDurationToJSON(message.duration);
    }
    return obj;
  },

  create(base?: DeepPartial<PutRateLimitRequest>): PutRateLimitRequest {
    return PutRateLimitRequest.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<PutRateLimitRequest>): PutRateLimitRequest {
    const message = createBasePutRateLimitRequest();
    message.key = object.key ?? '';
    message.limit = object.limit ?? 0;
    message.duration = object.duration ?? 0;
    return message;
  },
};

function createBasePutRateLimitResponse(): PutRateLimitResponse {
  return {};
}

export const PutRateLimitResponse: MessageFns<PutRateLimitResponse> = {
  encode(_: PutRateLimitResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): PutRateLimitResponse {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBasePutRateLimitResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(_: any): PutRateLimitResponse {
    return {};
  },

  toJSON(_: PutRateLimitResponse): unknown {
    const obj: any = {};
    return obj;
  },

  create(base?: DeepPartial<PutRateLimitResponse>): PutRateLimitResponse {
    return PutRateLimitResponse.fromPartial(base ?? {});
  },
  fromPartial(_: DeepPartial<PutRateLimitResponse>): PutRateLimitResponse {
    const message = createBasePutRateLimitResponse();
    return message;
  },
};

/** WorkflowService represents a set of RPCs for managing workflows. */
export type WorkflowServiceDefinition = typeof WorkflowServiceDefinition;
export const WorkflowServiceDefinition = {
  name: 'WorkflowService',
  fullName: 'WorkflowService',
  methods: {
    putWorkflow: {
      name: 'PutWorkflow',
      requestType: PutWorkflowRequest as typeof PutWorkflowRequest,
      requestStream: false,
      responseType: WorkflowVersion as typeof WorkflowVersion,
      responseStream: false,
      options: {},
    },
    scheduleWorkflow: {
      name: 'ScheduleWorkflow',
      requestType: ScheduleWorkflowRequest as typeof ScheduleWorkflowRequest,
      requestStream: false,
      responseType: WorkflowVersion as typeof WorkflowVersion,
      responseStream: false,
      options: {},
    },
    triggerWorkflow: {
      name: 'TriggerWorkflow',
      requestType: TriggerWorkflowRequest as typeof TriggerWorkflowRequest,
      requestStream: false,
      responseType: TriggerWorkflowResponse as typeof TriggerWorkflowResponse,
      responseStream: false,
      options: {},
    },
    bulkTriggerWorkflow: {
      name: 'BulkTriggerWorkflow',
      requestType: BulkTriggerWorkflowRequest as typeof BulkTriggerWorkflowRequest,
      requestStream: false,
      responseType: BulkTriggerWorkflowResponse as typeof BulkTriggerWorkflowResponse,
      responseStream: false,
      options: {},
    },
    putRateLimit: {
      name: 'PutRateLimit',
      requestType: PutRateLimitRequest as typeof PutRateLimitRequest,
      requestStream: false,
      responseType: PutRateLimitResponse as typeof PutRateLimitResponse,
      responseStream: false,
      options: {},
    },
  },
} as const;

export interface WorkflowServiceImplementation<CallContextExt = {}> {
  putWorkflow(
    request: PutWorkflowRequest,
    context: CallContext & CallContextExt
  ): Promise<DeepPartial<WorkflowVersion>>;
  scheduleWorkflow(
    request: ScheduleWorkflowRequest,
    context: CallContext & CallContextExt
  ): Promise<DeepPartial<WorkflowVersion>>;
  triggerWorkflow(
    request: TriggerWorkflowRequest,
    context: CallContext & CallContextExt
  ): Promise<DeepPartial<TriggerWorkflowResponse>>;
  bulkTriggerWorkflow(
    request: BulkTriggerWorkflowRequest,
    context: CallContext & CallContextExt
  ): Promise<DeepPartial<BulkTriggerWorkflowResponse>>;
  putRateLimit(
    request: PutRateLimitRequest,
    context: CallContext & CallContextExt
  ): Promise<DeepPartial<PutRateLimitResponse>>;
}

export interface WorkflowServiceClient<CallOptionsExt = {}> {
  putWorkflow(
    request: DeepPartial<PutWorkflowRequest>,
    options?: CallOptions & CallOptionsExt
  ): Promise<WorkflowVersion>;
  scheduleWorkflow(
    request: DeepPartial<ScheduleWorkflowRequest>,
    options?: CallOptions & CallOptionsExt
  ): Promise<WorkflowVersion>;
  triggerWorkflow(
    request: DeepPartial<TriggerWorkflowRequest>,
    options?: CallOptions & CallOptionsExt
  ): Promise<TriggerWorkflowResponse>;
  bulkTriggerWorkflow(
    request: DeepPartial<BulkTriggerWorkflowRequest>,
    options?: CallOptions & CallOptionsExt
  ): Promise<BulkTriggerWorkflowResponse>;
  putRateLimit(
    request: DeepPartial<PutRateLimitRequest>,
    options?: CallOptions & CallOptionsExt
  ): Promise<PutRateLimitResponse>;
}

type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin
  ? T
  : T extends globalThis.Array<infer U>
    ? globalThis.Array<DeepPartial<U>>
    : T extends ReadonlyArray<infer U>
      ? ReadonlyArray<DeepPartial<U>>
      : T extends {}
        ? { [K in keyof T]?: DeepPartial<T[K]> }
        : Partial<T>;

function toTimestamp(date: Date): Timestamp {
  const seconds = Math.trunc(date.getTime() / 1_000);
  const nanos = (date.getTime() % 1_000) * 1_000_000;
  return { seconds, nanos };
}

function fromTimestamp(t: Timestamp): Date {
  let millis = (t.seconds || 0) * 1_000;
  millis += (t.nanos || 0) / 1_000_000;
  return new globalThis.Date(millis);
}

function fromJsonTimestamp(o: any): Date {
  if (o instanceof globalThis.Date) {
    return o;
  } else if (typeof o === 'string') {
    return new globalThis.Date(o);
  } else {
    return fromTimestamp(Timestamp.fromJSON(o));
  }
}

function longToNumber(int64: { toString(): string }): number {
  const num = globalThis.Number(int64.toString());
  if (num > globalThis.Number.MAX_SAFE_INTEGER) {
    throw new globalThis.Error('Value is larger than Number.MAX_SAFE_INTEGER');
  }
  if (num < globalThis.Number.MIN_SAFE_INTEGER) {
    throw new globalThis.Error('Value is smaller than Number.MIN_SAFE_INTEGER');
  }
  return num;
}

function isObject(value: any): boolean {
  return typeof value === 'object' && value !== null;
}

function isSet(value: any): boolean {
  return value !== null && value !== undefined;
}

export interface MessageFns<T> {
  encode(message: T, writer?: BinaryWriter): BinaryWriter;
  decode(input: BinaryReader | Uint8Array, length?: number): T;
  fromJSON(object: any): T;
  toJSON(message: T): unknown;
  create(base?: DeepPartial<T>): T;
  fromPartial(object: DeepPartial<T>): T;
}
