// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
//   protoc-gen-ts_proto  v2.11.5
//   protoc               v7.34.1
// source: Contract.proto

/* eslint-disable */
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
import { ComboLeg } from "./ComboLeg.js";
import { DeltaNeutralContract } from "./DeltaNeutralContract.js";

export const protobufPackage = "protobuf";

export interface Contract {
  conId?: number | undefined;
  symbol?: string | undefined;
  secType?: string | undefined;
  lastTradeDateOrContractMonth?: string | undefined;
  strike?: number | undefined;
  right?: string | undefined;
  multiplier?: number | undefined;
  exchange?: string | undefined;
  primaryExch?: string | undefined;
  currency?: string | undefined;
  localSymbol?: string | undefined;
  tradingClass?: string | undefined;
  secIdType?: string | undefined;
  secId?: string | undefined;
  description?: string | undefined;
  issuerId?: string | undefined;
  deltaNeutralContract?: DeltaNeutralContract | undefined;
  includeExpired?: boolean | undefined;
  comboLegsDescrip?: string | undefined;
  comboLegs: ComboLeg[];
  lastTradeDate?: string | undefined;
}

function createBaseContract(): Contract {
  return {
    conId: undefined,
    symbol: undefined,
    secType: undefined,
    lastTradeDateOrContractMonth: undefined,
    strike: undefined,
    right: undefined,
    multiplier: undefined,
    exchange: undefined,
    primaryExch: undefined,
    currency: undefined,
    localSymbol: undefined,
    tradingClass: undefined,
    secIdType: undefined,
    secId: undefined,
    description: undefined,
    issuerId: undefined,
    deltaNeutralContract: undefined,
    includeExpired: undefined,
    comboLegsDescrip: undefined,
    comboLegs: [],
    lastTradeDate: undefined,
  };
}

export const Contract: MessageFns<Contract> = {
  encode(message: Contract, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.conId !== undefined) {
      writer.uint32(8).int32(message.conId);
    }
    if (message.symbol !== undefined) {
      writer.uint32(18).string(message.symbol);
    }
    if (message.secType !== undefined) {
      writer.uint32(26).string(message.secType);
    }
    if (message.lastTradeDateOrContractMonth !== undefined) {
      writer.uint32(34).string(message.lastTradeDateOrContractMonth);
    }
    if (message.strike !== undefined) {
      writer.uint32(41).double(message.strike);
    }
    if (message.right !== undefined) {
      writer.uint32(50).string(message.right);
    }
    if (message.multiplier !== undefined) {
      writer.uint32(57).double(message.multiplier);
    }
    if (message.exchange !== undefined) {
      writer.uint32(66).string(message.exchange);
    }
    if (message.primaryExch !== undefined) {
      writer.uint32(74).string(message.primaryExch);
    }
    if (message.currency !== undefined) {
      writer.uint32(82).string(message.currency);
    }
    if (message.localSymbol !== undefined) {
      writer.uint32(90).string(message.localSymbol);
    }
    if (message.tradingClass !== undefined) {
      writer.uint32(98).string(message.tradingClass);
    }
    if (message.secIdType !== undefined) {
      writer.uint32(106).string(message.secIdType);
    }
    if (message.secId !== undefined) {
      writer.uint32(114).string(message.secId);
    }
    if (message.description !== undefined) {
      writer.uint32(122).string(message.description);
    }
    if (message.issuerId !== undefined) {
      writer.uint32(130).string(message.issuerId);
    }
    if (message.deltaNeutralContract !== undefined) {
      DeltaNeutralContract.encode(message.deltaNeutralContract, writer.uint32(138).fork()).join();
    }
    if (message.includeExpired !== undefined) {
      writer.uint32(144).bool(message.includeExpired);
    }
    if (message.comboLegsDescrip !== undefined) {
      writer.uint32(154).string(message.comboLegsDescrip);
    }
    for (const v of message.comboLegs) {
      ComboLeg.encode(v!, writer.uint32(162).fork()).join();
    }
    if (message.lastTradeDate !== undefined) {
      writer.uint32(170).string(message.lastTradeDate);
    }
    return writer;
  },

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

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

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

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

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

          message.strike = reader.double();
          continue;
        }
        case 6: {
          if (tag !== 50) {
            break;
          }

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

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

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

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

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

          message.localSymbol = reader.string();
          continue;
        }
        case 12: {
          if (tag !== 98) {
            break;
          }

          message.tradingClass = reader.string();
          continue;
        }
        case 13: {
          if (tag !== 106) {
            break;
          }

          message.secIdType = reader.string();
          continue;
        }
        case 14: {
          if (tag !== 114) {
            break;
          }

          message.secId = reader.string();
          continue;
        }
        case 15: {
          if (tag !== 122) {
            break;
          }

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

          message.issuerId = reader.string();
          continue;
        }
        case 17: {
          if (tag !== 138) {
            break;
          }

          message.deltaNeutralContract = DeltaNeutralContract.decode(reader, reader.uint32());
          continue;
        }
        case 18: {
          if (tag !== 144) {
            break;
          }

          message.includeExpired = reader.bool();
          continue;
        }
        case 19: {
          if (tag !== 154) {
            break;
          }

          message.comboLegsDescrip = reader.string();
          continue;
        }
        case 20: {
          if (tag !== 162) {
            break;
          }

          message.comboLegs.push(ComboLeg.decode(reader, reader.uint32()));
          continue;
        }
        case 21: {
          if (tag !== 170) {
            break;
          }

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

  fromJSON(object: any): Contract {
    return {
      conId: isSet(object.conId) ? globalThis.Number(object.conId) : undefined,
      symbol: isSet(object.symbol) ? globalThis.String(object.symbol) : undefined,
      secType: isSet(object.secType) ? globalThis.String(object.secType) : undefined,
      lastTradeDateOrContractMonth: isSet(object.lastTradeDateOrContractMonth)
        ? globalThis.String(object.lastTradeDateOrContractMonth)
        : undefined,
      strike: isSet(object.strike) ? globalThis.Number(object.strike) : undefined,
      right: isSet(object.right) ? globalThis.String(object.right) : undefined,
      multiplier: isSet(object.multiplier) ? globalThis.Number(object.multiplier) : undefined,
      exchange: isSet(object.exchange) ? globalThis.String(object.exchange) : undefined,
      primaryExch: isSet(object.primaryExch) ? globalThis.String(object.primaryExch) : undefined,
      currency: isSet(object.currency) ? globalThis.String(object.currency) : undefined,
      localSymbol: isSet(object.localSymbol) ? globalThis.String(object.localSymbol) : undefined,
      tradingClass: isSet(object.tradingClass) ? globalThis.String(object.tradingClass) : undefined,
      secIdType: isSet(object.secIdType) ? globalThis.String(object.secIdType) : undefined,
      secId: isSet(object.secId) ? globalThis.String(object.secId) : undefined,
      description: isSet(object.description) ? globalThis.String(object.description) : undefined,
      issuerId: isSet(object.issuerId) ? globalThis.String(object.issuerId) : undefined,
      deltaNeutralContract: isSet(object.deltaNeutralContract)
        ? DeltaNeutralContract.fromJSON(object.deltaNeutralContract)
        : undefined,
      includeExpired: isSet(object.includeExpired) ? globalThis.Boolean(object.includeExpired) : undefined,
      comboLegsDescrip: isSet(object.comboLegsDescrip) ? globalThis.String(object.comboLegsDescrip) : undefined,
      comboLegs: globalThis.Array.isArray(object?.comboLegs)
        ? object.comboLegs.map((e: any) => ComboLeg.fromJSON(e))
        : [],
      lastTradeDate: isSet(object.lastTradeDate) ? globalThis.String(object.lastTradeDate) : undefined,
    };
  },

  toJSON(message: Contract): unknown {
    const obj: any = {};
    if (message.conId !== undefined) {
      obj.conId = Math.round(message.conId);
    }
    if (message.symbol !== undefined) {
      obj.symbol = message.symbol;
    }
    if (message.secType !== undefined) {
      obj.secType = message.secType;
    }
    if (message.lastTradeDateOrContractMonth !== undefined) {
      obj.lastTradeDateOrContractMonth = message.lastTradeDateOrContractMonth;
    }
    if (message.strike !== undefined) {
      obj.strike = message.strike;
    }
    if (message.right !== undefined) {
      obj.right = message.right;
    }
    if (message.multiplier !== undefined) {
      obj.multiplier = message.multiplier;
    }
    if (message.exchange !== undefined) {
      obj.exchange = message.exchange;
    }
    if (message.primaryExch !== undefined) {
      obj.primaryExch = message.primaryExch;
    }
    if (message.currency !== undefined) {
      obj.currency = message.currency;
    }
    if (message.localSymbol !== undefined) {
      obj.localSymbol = message.localSymbol;
    }
    if (message.tradingClass !== undefined) {
      obj.tradingClass = message.tradingClass;
    }
    if (message.secIdType !== undefined) {
      obj.secIdType = message.secIdType;
    }
    if (message.secId !== undefined) {
      obj.secId = message.secId;
    }
    if (message.description !== undefined) {
      obj.description = message.description;
    }
    if (message.issuerId !== undefined) {
      obj.issuerId = message.issuerId;
    }
    if (message.deltaNeutralContract !== undefined) {
      obj.deltaNeutralContract = DeltaNeutralContract.toJSON(message.deltaNeutralContract);
    }
    if (message.includeExpired !== undefined) {
      obj.includeExpired = message.includeExpired;
    }
    if (message.comboLegsDescrip !== undefined) {
      obj.comboLegsDescrip = message.comboLegsDescrip;
    }
    if (message.comboLegs?.length) {
      obj.comboLegs = message.comboLegs.map((e) => ComboLeg.toJSON(e));
    }
    if (message.lastTradeDate !== undefined) {
      obj.lastTradeDate = message.lastTradeDate;
    }
    return obj;
  },

  create(base?: DeepPartial<Contract>): Contract {
    return Contract.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<Contract>): Contract {
    const message = createBaseContract();
    message.conId = object.conId ?? undefined;
    message.symbol = object.symbol ?? undefined;
    message.secType = object.secType ?? undefined;
    message.lastTradeDateOrContractMonth = object.lastTradeDateOrContractMonth ?? undefined;
    message.strike = object.strike ?? undefined;
    message.right = object.right ?? undefined;
    message.multiplier = object.multiplier ?? undefined;
    message.exchange = object.exchange ?? undefined;
    message.primaryExch = object.primaryExch ?? undefined;
    message.currency = object.currency ?? undefined;
    message.localSymbol = object.localSymbol ?? undefined;
    message.tradingClass = object.tradingClass ?? undefined;
    message.secIdType = object.secIdType ?? undefined;
    message.secId = object.secId ?? undefined;
    message.description = object.description ?? undefined;
    message.issuerId = object.issuerId ?? undefined;
    message.deltaNeutralContract = (object.deltaNeutralContract !== undefined && object.deltaNeutralContract !== null)
      ? DeltaNeutralContract.fromPartial(object.deltaNeutralContract)
      : undefined;
    message.includeExpired = object.includeExpired ?? undefined;
    message.comboLegsDescrip = object.comboLegsDescrip ?? undefined;
    message.comboLegs = object.comboLegs?.map((e) => ComboLeg.fromPartial(e)) || [];
    message.lastTradeDate = object.lastTradeDate ?? undefined;
    return message;
  },
};

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 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;
}
