// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
//   protoc-gen-ts_proto  v2.6.1
//   protoc               unknown
// source: api/v1/instance_service.proto

/* eslint-disable */
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
import { FieldMask } from "../../google/protobuf/field_mask";

export const protobufPackage = "memos.api.v1";

/** Instance profile message containing basic instance information. */
export interface InstanceProfile {
  /**
   * The name of instance owner.
   * Format: users/{user}
   */
  owner: string;
  /** Version is the current version of instance. */
  version: string;
  /** Mode is the instance mode (e.g. "prod", "dev" or "demo"). */
  mode: string;
  /** Instance URL is the URL of the instance. */
  instanceUrl: string;
}

/** Request for instance profile. */
export interface GetInstanceProfileRequest {
}

/** An instance setting resource. */
export interface InstanceSetting {
  /**
   * The name of the instance setting.
   * Format: instance/settings/{setting}
   */
  name: string;
  generalSetting?: InstanceSetting_GeneralSetting | undefined;
  storageSetting?: InstanceSetting_StorageSetting | undefined;
  memoRelatedSetting?: InstanceSetting_MemoRelatedSetting | undefined;
}

/** Enumeration of instance setting keys. */
export enum InstanceSetting_Key {
  KEY_UNSPECIFIED = "KEY_UNSPECIFIED",
  /** GENERAL - GENERAL is the key for general settings. */
  GENERAL = "GENERAL",
  /** STORAGE - STORAGE is the key for storage settings. */
  STORAGE = "STORAGE",
  /** MEMO_RELATED - MEMO_RELATED is the key for memo related settings. */
  MEMO_RELATED = "MEMO_RELATED",
  UNRECOGNIZED = "UNRECOGNIZED",
}

export function instanceSetting_KeyFromJSON(object: any): InstanceSetting_Key {
  switch (object) {
    case 0:
    case "KEY_UNSPECIFIED":
      return InstanceSetting_Key.KEY_UNSPECIFIED;
    case 1:
    case "GENERAL":
      return InstanceSetting_Key.GENERAL;
    case 2:
    case "STORAGE":
      return InstanceSetting_Key.STORAGE;
    case 3:
    case "MEMO_RELATED":
      return InstanceSetting_Key.MEMO_RELATED;
    case -1:
    case "UNRECOGNIZED":
    default:
      return InstanceSetting_Key.UNRECOGNIZED;
  }
}

export function instanceSetting_KeyToNumber(object: InstanceSetting_Key): number {
  switch (object) {
    case InstanceSetting_Key.KEY_UNSPECIFIED:
      return 0;
    case InstanceSetting_Key.GENERAL:
      return 1;
    case InstanceSetting_Key.STORAGE:
      return 2;
    case InstanceSetting_Key.MEMO_RELATED:
      return 3;
    case InstanceSetting_Key.UNRECOGNIZED:
    default:
      return -1;
  }
}

/** General instance settings configuration. */
export interface InstanceSetting_GeneralSetting {
  /**
   * theme is the name of the selected theme.
   * This references a CSS file in the web/public/themes/ directory.
   */
  theme: string;
  /** disallow_user_registration disallows user registration. */
  disallowUserRegistration: boolean;
  /** disallow_password_auth disallows password authentication. */
  disallowPasswordAuth: boolean;
  /** additional_script is the additional script. */
  additionalScript: string;
  /** additional_style is the additional style. */
  additionalStyle: string;
  /** custom_profile is the custom profile. */
  customProfile?:
    | InstanceSetting_GeneralSetting_CustomProfile
    | undefined;
  /**
   * week_start_day_offset is the week start day offset from Sunday.
   * 0: Sunday, 1: Monday, 2: Tuesday, 3: Wednesday, 4: Thursday, 5: Friday, 6: Saturday
   * Default is Sunday.
   */
  weekStartDayOffset: number;
  /** disallow_change_username disallows changing username. */
  disallowChangeUsername: boolean;
  /** disallow_change_nickname disallows changing nickname. */
  disallowChangeNickname: boolean;
}

/** Custom profile configuration for instance branding. */
export interface InstanceSetting_GeneralSetting_CustomProfile {
  title: string;
  description: string;
  logoUrl: string;
  locale: string;
}

/** Storage configuration settings for instance attachments. */
export interface InstanceSetting_StorageSetting {
  /** storage_type is the storage type. */
  storageType: InstanceSetting_StorageSetting_StorageType;
  /**
   * The template of file path.
   * e.g. assets/{timestamp}_{filename}
   */
  filepathTemplate: string;
  /** The max upload size in megabytes. */
  uploadSizeLimitMb: number;
  /** The S3 config. */
  s3Config?: InstanceSetting_StorageSetting_S3Config | undefined;
}

/** Storage type enumeration for different storage backends. */
export enum InstanceSetting_StorageSetting_StorageType {
  STORAGE_TYPE_UNSPECIFIED = "STORAGE_TYPE_UNSPECIFIED",
  /** DATABASE - DATABASE is the database storage type. */
  DATABASE = "DATABASE",
  /** LOCAL - LOCAL is the local storage type. */
  LOCAL = "LOCAL",
  /** S3 - S3 is the S3 storage type. */
  S3 = "S3",
  UNRECOGNIZED = "UNRECOGNIZED",
}

export function instanceSetting_StorageSetting_StorageTypeFromJSON(
  object: any,
): InstanceSetting_StorageSetting_StorageType {
  switch (object) {
    case 0:
    case "STORAGE_TYPE_UNSPECIFIED":
      return InstanceSetting_StorageSetting_StorageType.STORAGE_TYPE_UNSPECIFIED;
    case 1:
    case "DATABASE":
      return InstanceSetting_StorageSetting_StorageType.DATABASE;
    case 2:
    case "LOCAL":
      return InstanceSetting_StorageSetting_StorageType.LOCAL;
    case 3:
    case "S3":
      return InstanceSetting_StorageSetting_StorageType.S3;
    case -1:
    case "UNRECOGNIZED":
    default:
      return InstanceSetting_StorageSetting_StorageType.UNRECOGNIZED;
  }
}

export function instanceSetting_StorageSetting_StorageTypeToNumber(
  object: InstanceSetting_StorageSetting_StorageType,
): number {
  switch (object) {
    case InstanceSetting_StorageSetting_StorageType.STORAGE_TYPE_UNSPECIFIED:
      return 0;
    case InstanceSetting_StorageSetting_StorageType.DATABASE:
      return 1;
    case InstanceSetting_StorageSetting_StorageType.LOCAL:
      return 2;
    case InstanceSetting_StorageSetting_StorageType.S3:
      return 3;
    case InstanceSetting_StorageSetting_StorageType.UNRECOGNIZED:
    default:
      return -1;
  }
}

/**
 * S3 configuration for cloud storage backend.
 * Reference: https://developers.cloudflare.com/r2/examples/aws/aws-sdk-go/
 */
export interface InstanceSetting_StorageSetting_S3Config {
  accessKeyId: string;
  accessKeySecret: string;
  endpoint: string;
  region: string;
  bucket: string;
  usePathStyle: boolean;
}

/** Memo-related instance settings and policies. */
export interface InstanceSetting_MemoRelatedSetting {
  /** disallow_public_visibility disallows set memo as public visibility. */
  disallowPublicVisibility: boolean;
  /** display_with_update_time orders and displays memo with update time. */
  displayWithUpdateTime: boolean;
  /** content_length_limit is the limit of content length. Unit is byte. */
  contentLengthLimit: number;
  /** enable_double_click_edit enables editing on double click. */
  enableDoubleClickEdit: boolean;
  /** enable_link_preview enables links preview. */
  enableLinkPreview: boolean;
  /** reactions is the list of reactions. */
  reactions: string[];
  /** enable_blur_nsfw_content enables blurring of content marked as not safe for work (NSFW). */
  enableBlurNsfwContent: boolean;
  /** nsfw_tags is the list of tags that mark content as NSFW for blurring. */
  nsfwTags: string[];
}

/** Request message for GetInstanceSetting method. */
export interface GetInstanceSettingRequest {
  /**
   * The resource name of the instance setting.
   * Format: instance/settings/{setting}
   */
  name: string;
}

/** Request message for UpdateInstanceSetting method. */
export interface UpdateInstanceSettingRequest {
  /** The instance setting resource which replaces the resource on the server. */
  setting?:
    | InstanceSetting
    | undefined;
  /** The list of fields to update. */
  updateMask?: string[] | undefined;
}

function createBaseInstanceProfile(): InstanceProfile {
  return { owner: "", version: "", mode: "", instanceUrl: "" };
}

export const InstanceProfile: MessageFns<InstanceProfile> = {
  encode(message: InstanceProfile, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.owner !== "") {
      writer.uint32(10).string(message.owner);
    }
    if (message.version !== "") {
      writer.uint32(18).string(message.version);
    }
    if (message.mode !== "") {
      writer.uint32(26).string(message.mode);
    }
    if (message.instanceUrl !== "") {
      writer.uint32(50).string(message.instanceUrl);
    }
    return writer;
  },

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

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

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

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

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

  create(base?: DeepPartial<InstanceProfile>): InstanceProfile {
    return InstanceProfile.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<InstanceProfile>): InstanceProfile {
    const message = createBaseInstanceProfile();
    message.owner = object.owner ?? "";
    message.version = object.version ?? "";
    message.mode = object.mode ?? "";
    message.instanceUrl = object.instanceUrl ?? "";
    return message;
  },
};

function createBaseGetInstanceProfileRequest(): GetInstanceProfileRequest {
  return {};
}

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

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

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

function createBaseInstanceSetting(): InstanceSetting {
  return { name: "", generalSetting: undefined, storageSetting: undefined, memoRelatedSetting: undefined };
}

export const InstanceSetting: MessageFns<InstanceSetting> = {
  encode(message: InstanceSetting, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.name !== "") {
      writer.uint32(10).string(message.name);
    }
    if (message.generalSetting !== undefined) {
      InstanceSetting_GeneralSetting.encode(message.generalSetting, writer.uint32(18).fork()).join();
    }
    if (message.storageSetting !== undefined) {
      InstanceSetting_StorageSetting.encode(message.storageSetting, writer.uint32(26).fork()).join();
    }
    if (message.memoRelatedSetting !== undefined) {
      InstanceSetting_MemoRelatedSetting.encode(message.memoRelatedSetting, writer.uint32(34).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): InstanceSetting {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseInstanceSetting();
    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.generalSetting = InstanceSetting_GeneralSetting.decode(reader, reader.uint32());
          continue;
        }
        case 3: {
          if (tag !== 26) {
            break;
          }

          message.storageSetting = InstanceSetting_StorageSetting.decode(reader, reader.uint32());
          continue;
        }
        case 4: {
          if (tag !== 34) {
            break;
          }

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

  create(base?: DeepPartial<InstanceSetting>): InstanceSetting {
    return InstanceSetting.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<InstanceSetting>): InstanceSetting {
    const message = createBaseInstanceSetting();
    message.name = object.name ?? "";
    message.generalSetting = (object.generalSetting !== undefined && object.generalSetting !== null)
      ? InstanceSetting_GeneralSetting.fromPartial(object.generalSetting)
      : undefined;
    message.storageSetting = (object.storageSetting !== undefined && object.storageSetting !== null)
      ? InstanceSetting_StorageSetting.fromPartial(object.storageSetting)
      : undefined;
    message.memoRelatedSetting = (object.memoRelatedSetting !== undefined && object.memoRelatedSetting !== null)
      ? InstanceSetting_MemoRelatedSetting.fromPartial(object.memoRelatedSetting)
      : undefined;
    return message;
  },
};

function createBaseInstanceSetting_GeneralSetting(): InstanceSetting_GeneralSetting {
  return {
    theme: "",
    disallowUserRegistration: false,
    disallowPasswordAuth: false,
    additionalScript: "",
    additionalStyle: "",
    customProfile: undefined,
    weekStartDayOffset: 0,
    disallowChangeUsername: false,
    disallowChangeNickname: false,
  };
}

export const InstanceSetting_GeneralSetting: MessageFns<InstanceSetting_GeneralSetting> = {
  encode(message: InstanceSetting_GeneralSetting, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.theme !== "") {
      writer.uint32(10).string(message.theme);
    }
    if (message.disallowUserRegistration !== false) {
      writer.uint32(16).bool(message.disallowUserRegistration);
    }
    if (message.disallowPasswordAuth !== false) {
      writer.uint32(24).bool(message.disallowPasswordAuth);
    }
    if (message.additionalScript !== "") {
      writer.uint32(34).string(message.additionalScript);
    }
    if (message.additionalStyle !== "") {
      writer.uint32(42).string(message.additionalStyle);
    }
    if (message.customProfile !== undefined) {
      InstanceSetting_GeneralSetting_CustomProfile.encode(message.customProfile, writer.uint32(50).fork()).join();
    }
    if (message.weekStartDayOffset !== 0) {
      writer.uint32(56).int32(message.weekStartDayOffset);
    }
    if (message.disallowChangeUsername !== false) {
      writer.uint32(64).bool(message.disallowChangeUsername);
    }
    if (message.disallowChangeNickname !== false) {
      writer.uint32(72).bool(message.disallowChangeNickname);
    }
    return writer;
  },

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

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

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

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

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

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

          message.customProfile = InstanceSetting_GeneralSetting_CustomProfile.decode(reader, reader.uint32());
          continue;
        }
        case 7: {
          if (tag !== 56) {
            break;
          }

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

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

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

  create(base?: DeepPartial<InstanceSetting_GeneralSetting>): InstanceSetting_GeneralSetting {
    return InstanceSetting_GeneralSetting.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<InstanceSetting_GeneralSetting>): InstanceSetting_GeneralSetting {
    const message = createBaseInstanceSetting_GeneralSetting();
    message.theme = object.theme ?? "";
    message.disallowUserRegistration = object.disallowUserRegistration ?? false;
    message.disallowPasswordAuth = object.disallowPasswordAuth ?? false;
    message.additionalScript = object.additionalScript ?? "";
    message.additionalStyle = object.additionalStyle ?? "";
    message.customProfile = (object.customProfile !== undefined && object.customProfile !== null)
      ? InstanceSetting_GeneralSetting_CustomProfile.fromPartial(object.customProfile)
      : undefined;
    message.weekStartDayOffset = object.weekStartDayOffset ?? 0;
    message.disallowChangeUsername = object.disallowChangeUsername ?? false;
    message.disallowChangeNickname = object.disallowChangeNickname ?? false;
    return message;
  },
};

function createBaseInstanceSetting_GeneralSetting_CustomProfile(): InstanceSetting_GeneralSetting_CustomProfile {
  return { title: "", description: "", logoUrl: "", locale: "" };
}

export const InstanceSetting_GeneralSetting_CustomProfile: MessageFns<InstanceSetting_GeneralSetting_CustomProfile> = {
  encode(
    message: InstanceSetting_GeneralSetting_CustomProfile,
    writer: BinaryWriter = new BinaryWriter(),
  ): BinaryWriter {
    if (message.title !== "") {
      writer.uint32(10).string(message.title);
    }
    if (message.description !== "") {
      writer.uint32(18).string(message.description);
    }
    if (message.logoUrl !== "") {
      writer.uint32(26).string(message.logoUrl);
    }
    if (message.locale !== "") {
      writer.uint32(34).string(message.locale);
    }
    return writer;
  },

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

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

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

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

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

  create(
    base?: DeepPartial<InstanceSetting_GeneralSetting_CustomProfile>,
  ): InstanceSetting_GeneralSetting_CustomProfile {
    return InstanceSetting_GeneralSetting_CustomProfile.fromPartial(base ?? {});
  },
  fromPartial(
    object: DeepPartial<InstanceSetting_GeneralSetting_CustomProfile>,
  ): InstanceSetting_GeneralSetting_CustomProfile {
    const message = createBaseInstanceSetting_GeneralSetting_CustomProfile();
    message.title = object.title ?? "";
    message.description = object.description ?? "";
    message.logoUrl = object.logoUrl ?? "";
    message.locale = object.locale ?? "";
    return message;
  },
};

function createBaseInstanceSetting_StorageSetting(): InstanceSetting_StorageSetting {
  return {
    storageType: InstanceSetting_StorageSetting_StorageType.STORAGE_TYPE_UNSPECIFIED,
    filepathTemplate: "",
    uploadSizeLimitMb: 0,
    s3Config: undefined,
  };
}

export const InstanceSetting_StorageSetting: MessageFns<InstanceSetting_StorageSetting> = {
  encode(message: InstanceSetting_StorageSetting, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.storageType !== InstanceSetting_StorageSetting_StorageType.STORAGE_TYPE_UNSPECIFIED) {
      writer.uint32(8).int32(instanceSetting_StorageSetting_StorageTypeToNumber(message.storageType));
    }
    if (message.filepathTemplate !== "") {
      writer.uint32(18).string(message.filepathTemplate);
    }
    if (message.uploadSizeLimitMb !== 0) {
      writer.uint32(24).int64(message.uploadSizeLimitMb);
    }
    if (message.s3Config !== undefined) {
      InstanceSetting_StorageSetting_S3Config.encode(message.s3Config, writer.uint32(34).fork()).join();
    }
    return writer;
  },

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

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

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

          message.uploadSizeLimitMb = longToNumber(reader.int64());
          continue;
        }
        case 4: {
          if (tag !== 34) {
            break;
          }

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

  create(base?: DeepPartial<InstanceSetting_StorageSetting>): InstanceSetting_StorageSetting {
    return InstanceSetting_StorageSetting.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<InstanceSetting_StorageSetting>): InstanceSetting_StorageSetting {
    const message = createBaseInstanceSetting_StorageSetting();
    message.storageType = object.storageType ?? InstanceSetting_StorageSetting_StorageType.STORAGE_TYPE_UNSPECIFIED;
    message.filepathTemplate = object.filepathTemplate ?? "";
    message.uploadSizeLimitMb = object.uploadSizeLimitMb ?? 0;
    message.s3Config = (object.s3Config !== undefined && object.s3Config !== null)
      ? InstanceSetting_StorageSetting_S3Config.fromPartial(object.s3Config)
      : undefined;
    return message;
  },
};

function createBaseInstanceSetting_StorageSetting_S3Config(): InstanceSetting_StorageSetting_S3Config {
  return { accessKeyId: "", accessKeySecret: "", endpoint: "", region: "", bucket: "", usePathStyle: false };
}

export const InstanceSetting_StorageSetting_S3Config: MessageFns<InstanceSetting_StorageSetting_S3Config> = {
  encode(message: InstanceSetting_StorageSetting_S3Config, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.accessKeyId !== "") {
      writer.uint32(10).string(message.accessKeyId);
    }
    if (message.accessKeySecret !== "") {
      writer.uint32(18).string(message.accessKeySecret);
    }
    if (message.endpoint !== "") {
      writer.uint32(26).string(message.endpoint);
    }
    if (message.region !== "") {
      writer.uint32(34).string(message.region);
    }
    if (message.bucket !== "") {
      writer.uint32(42).string(message.bucket);
    }
    if (message.usePathStyle !== false) {
      writer.uint32(48).bool(message.usePathStyle);
    }
    return writer;
  },

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

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

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

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

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

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

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

  create(base?: DeepPartial<InstanceSetting_StorageSetting_S3Config>): InstanceSetting_StorageSetting_S3Config {
    return InstanceSetting_StorageSetting_S3Config.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<InstanceSetting_StorageSetting_S3Config>): InstanceSetting_StorageSetting_S3Config {
    const message = createBaseInstanceSetting_StorageSetting_S3Config();
    message.accessKeyId = object.accessKeyId ?? "";
    message.accessKeySecret = object.accessKeySecret ?? "";
    message.endpoint = object.endpoint ?? "";
    message.region = object.region ?? "";
    message.bucket = object.bucket ?? "";
    message.usePathStyle = object.usePathStyle ?? false;
    return message;
  },
};

function createBaseInstanceSetting_MemoRelatedSetting(): InstanceSetting_MemoRelatedSetting {
  return {
    disallowPublicVisibility: false,
    displayWithUpdateTime: false,
    contentLengthLimit: 0,
    enableDoubleClickEdit: false,
    enableLinkPreview: false,
    reactions: [],
    enableBlurNsfwContent: false,
    nsfwTags: [],
  };
}

export const InstanceSetting_MemoRelatedSetting: MessageFns<InstanceSetting_MemoRelatedSetting> = {
  encode(message: InstanceSetting_MemoRelatedSetting, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.disallowPublicVisibility !== false) {
      writer.uint32(8).bool(message.disallowPublicVisibility);
    }
    if (message.displayWithUpdateTime !== false) {
      writer.uint32(16).bool(message.displayWithUpdateTime);
    }
    if (message.contentLengthLimit !== 0) {
      writer.uint32(24).int32(message.contentLengthLimit);
    }
    if (message.enableDoubleClickEdit !== false) {
      writer.uint32(32).bool(message.enableDoubleClickEdit);
    }
    if (message.enableLinkPreview !== false) {
      writer.uint32(40).bool(message.enableLinkPreview);
    }
    for (const v of message.reactions) {
      writer.uint32(58).string(v!);
    }
    if (message.enableBlurNsfwContent !== false) {
      writer.uint32(72).bool(message.enableBlurNsfwContent);
    }
    for (const v of message.nsfwTags) {
      writer.uint32(82).string(v!);
    }
    return writer;
  },

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

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

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

          message.contentLengthLimit = reader.int32();
          continue;
        }
        case 4: {
          if (tag !== 32) {
            break;
          }

          message.enableDoubleClickEdit = reader.bool();
          continue;
        }
        case 5: {
          if (tag !== 40) {
            break;
          }

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

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

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

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

  create(base?: DeepPartial<InstanceSetting_MemoRelatedSetting>): InstanceSetting_MemoRelatedSetting {
    return InstanceSetting_MemoRelatedSetting.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<InstanceSetting_MemoRelatedSetting>): InstanceSetting_MemoRelatedSetting {
    const message = createBaseInstanceSetting_MemoRelatedSetting();
    message.disallowPublicVisibility = object.disallowPublicVisibility ?? false;
    message.displayWithUpdateTime = object.displayWithUpdateTime ?? false;
    message.contentLengthLimit = object.contentLengthLimit ?? 0;
    message.enableDoubleClickEdit = object.enableDoubleClickEdit ?? false;
    message.enableLinkPreview = object.enableLinkPreview ?? false;
    message.reactions = object.reactions?.map((e) => e) || [];
    message.enableBlurNsfwContent = object.enableBlurNsfwContent ?? false;
    message.nsfwTags = object.nsfwTags?.map((e) => e) || [];
    return message;
  },
};

function createBaseGetInstanceSettingRequest(): GetInstanceSettingRequest {
  return { name: "" };
}

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

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

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

  create(base?: DeepPartial<GetInstanceSettingRequest>): GetInstanceSettingRequest {
    return GetInstanceSettingRequest.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<GetInstanceSettingRequest>): GetInstanceSettingRequest {
    const message = createBaseGetInstanceSettingRequest();
    message.name = object.name ?? "";
    return message;
  },
};

function createBaseUpdateInstanceSettingRequest(): UpdateInstanceSettingRequest {
  return { setting: undefined, updateMask: undefined };
}

export const UpdateInstanceSettingRequest: MessageFns<UpdateInstanceSettingRequest> = {
  encode(message: UpdateInstanceSettingRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.setting !== undefined) {
      InstanceSetting.encode(message.setting, writer.uint32(10).fork()).join();
    }
    if (message.updateMask !== undefined) {
      FieldMask.encode(FieldMask.wrap(message.updateMask), writer.uint32(18).fork()).join();
    }
    return writer;
  },

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

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

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

  create(base?: DeepPartial<UpdateInstanceSettingRequest>): UpdateInstanceSettingRequest {
    return UpdateInstanceSettingRequest.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<UpdateInstanceSettingRequest>): UpdateInstanceSettingRequest {
    const message = createBaseUpdateInstanceSettingRequest();
    message.setting = (object.setting !== undefined && object.setting !== null)
      ? InstanceSetting.fromPartial(object.setting)
      : undefined;
    message.updateMask = object.updateMask ?? undefined;
    return message;
  },
};

export type InstanceServiceDefinition = typeof InstanceServiceDefinition;
export const InstanceServiceDefinition = {
  name: "InstanceService",
  fullName: "memos.api.v1.InstanceService",
  methods: {
    /** Gets the instance profile. */
    getInstanceProfile: {
      name: "GetInstanceProfile",
      requestType: GetInstanceProfileRequest,
      requestStream: false,
      responseType: InstanceProfile,
      responseStream: false,
      options: {
        _unknownFields: {
          578365826: [
            new Uint8Array([
              26,
              18,
              24,
              47,
              97,
              112,
              105,
              47,
              118,
              49,
              47,
              105,
              110,
              115,
              116,
              97,
              110,
              99,
              101,
              47,
              112,
              114,
              111,
              102,
              105,
              108,
              101,
            ]),
          ],
        },
      },
    },
    /** Gets an instance setting. */
    getInstanceSetting: {
      name: "GetInstanceSetting",
      requestType: GetInstanceSettingRequest,
      requestStream: false,
      responseType: InstanceSetting,
      responseStream: false,
      options: {
        _unknownFields: {
          8410: [new Uint8Array([4, 110, 97, 109, 101])],
          578365826: [
            new Uint8Array([
              36,
              18,
              34,
              47,
              97,
              112,
              105,
              47,
              118,
              49,
              47,
              123,
              110,
              97,
              109,
              101,
              61,
              105,
              110,
              115,
              116,
              97,
              110,
              99,
              101,
              47,
              115,
              101,
              116,
              116,
              105,
              110,
              103,
              115,
              47,
              42,
              125,
            ]),
          ],
        },
      },
    },
    /** Updates an instance setting. */
    updateInstanceSetting: {
      name: "UpdateInstanceSetting",
      requestType: UpdateInstanceSettingRequest,
      requestStream: false,
      responseType: InstanceSetting,
      responseStream: false,
      options: {
        _unknownFields: {
          8410: [
            new Uint8Array([
              19,
              115,
              101,
              116,
              116,
              105,
              110,
              103,
              44,
              117,
              112,
              100,
              97,
              116,
              101,
              95,
              109,
              97,
              115,
              107,
            ]),
          ],
          578365826: [
            new Uint8Array([
              53,
              58,
              7,
              115,
              101,
              116,
              116,
              105,
              110,
              103,
              50,
              42,
              47,
              97,
              112,
              105,
              47,
              118,
              49,
              47,
              123,
              115,
              101,
              116,
              116,
              105,
              110,
              103,
              46,
              110,
              97,
              109,
              101,
              61,
              105,
              110,
              115,
              116,
              97,
              110,
              99,
              101,
              47,
              115,
              101,
              116,
              116,
              105,
              110,
              103,
              115,
              47,
              42,
              125,
            ]),
          ],
        },
      },
    },
  },
} as const;

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

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