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

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

export const protobufPackage = "protobuf";

export interface PortfolioValue {
  contract?: Contract | undefined;
  position?: string | undefined;
  marketPrice?: number | undefined;
  marketValue?: number | undefined;
  averageCost?: number | undefined;
  unrealizedPNL?: number | undefined;
  realizedPNL?: number | undefined;
  accountName?: string | undefined;
}

function createBasePortfolioValue(): PortfolioValue {
  return {
    contract: undefined,
    position: undefined,
    marketPrice: undefined,
    marketValue: undefined,
    averageCost: undefined,
    unrealizedPNL: undefined,
    realizedPNL: undefined,
    accountName: undefined,
  };
}

export const PortfolioValue: MessageFns<PortfolioValue> = {
  encode(message: PortfolioValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.contract !== undefined) {
      Contract.encode(message.contract, writer.uint32(10).fork()).join();
    }
    if (message.position !== undefined) {
      writer.uint32(18).string(message.position);
    }
    if (message.marketPrice !== undefined) {
      writer.uint32(25).double(message.marketPrice);
    }
    if (message.marketValue !== undefined) {
      writer.uint32(33).double(message.marketValue);
    }
    if (message.averageCost !== undefined) {
      writer.uint32(41).double(message.averageCost);
    }
    if (message.unrealizedPNL !== undefined) {
      writer.uint32(49).double(message.unrealizedPNL);
    }
    if (message.realizedPNL !== undefined) {
      writer.uint32(57).double(message.realizedPNL);
    }
    if (message.accountName !== undefined) {
      writer.uint32(66).string(message.accountName);
    }
    return writer;
  },

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

          message.contract = Contract.decode(reader, reader.uint32());
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

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

          message.marketPrice = reader.double();
          continue;
        }
        case 4: {
          if (tag !== 33) {
            break;
          }

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

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

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

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

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

  fromJSON(object: any): PortfolioValue {
    return {
      contract: isSet(object.contract) ? Contract.fromJSON(object.contract) : undefined,
      position: isSet(object.position) ? globalThis.String(object.position) : undefined,
      marketPrice: isSet(object.marketPrice) ? globalThis.Number(object.marketPrice) : undefined,
      marketValue: isSet(object.marketValue) ? globalThis.Number(object.marketValue) : undefined,
      averageCost: isSet(object.averageCost) ? globalThis.Number(object.averageCost) : undefined,
      unrealizedPNL: isSet(object.unrealizedPNL) ? globalThis.Number(object.unrealizedPNL) : undefined,
      realizedPNL: isSet(object.realizedPNL) ? globalThis.Number(object.realizedPNL) : undefined,
      accountName: isSet(object.accountName) ? globalThis.String(object.accountName) : undefined,
    };
  },

  toJSON(message: PortfolioValue): unknown {
    const obj: any = {};
    if (message.contract !== undefined) {
      obj.contract = Contract.toJSON(message.contract);
    }
    if (message.position !== undefined) {
      obj.position = message.position;
    }
    if (message.marketPrice !== undefined) {
      obj.marketPrice = message.marketPrice;
    }
    if (message.marketValue !== undefined) {
      obj.marketValue = message.marketValue;
    }
    if (message.averageCost !== undefined) {
      obj.averageCost = message.averageCost;
    }
    if (message.unrealizedPNL !== undefined) {
      obj.unrealizedPNL = message.unrealizedPNL;
    }
    if (message.realizedPNL !== undefined) {
      obj.realizedPNL = message.realizedPNL;
    }
    if (message.accountName !== undefined) {
      obj.accountName = message.accountName;
    }
    return obj;
  },

  create(base?: DeepPartial<PortfolioValue>): PortfolioValue {
    return PortfolioValue.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<PortfolioValue>): PortfolioValue {
    const message = createBasePortfolioValue();
    message.contract = (object.contract !== undefined && object.contract !== null)
      ? Contract.fromPartial(object.contract)
      : undefined;
    message.position = object.position ?? undefined;
    message.marketPrice = object.marketPrice ?? undefined;
    message.marketValue = object.marketValue ?? undefined;
    message.averageCost = object.averageCost ?? undefined;
    message.unrealizedPNL = object.unrealizedPNL ?? undefined;
    message.realizedPNL = object.realizedPNL ?? undefined;
    message.accountName = object.accountName ?? 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;
}
