import smugmug from "../../smugmug.app.mjs";
import constants from "../../common/constants.mjs";
export default {
  key: "smugmug-create-album",
  name: "Create Album",
  description: "Creates an album. [See the docs here](https://api.smugmug.com/api/v2/doc/reference/album.html)",
  version: "2.0.2",
  annotations: {
    destructiveHint: false,
    openWorldHint: true,
    readOnlyHint: false,
  },
  type: "action",
  props: {
    smugmug,
    folder: {
      propDefinition: [
        smugmug,
        "folder",
      ],
    },
    title: {
      type: "string",
      label: "Title",
      description: "The human-readable title.",
    },
    niceName: {
      type: "string",
      label: "Nice Name",
      description: "The user-configurable component of the album's webUri. Must begin with a capital letter.",
    },
    urlName: {
      type: "string",
      label: "URL Name",
      description: "The user-configurable component of the album's webUri.",
      optional: true,
    },
    privacy: {
      type: "string",
      label: "Privacy",
      description: "Private is not supported on legacy accounts.\nIt can be Private, Unlisted, or Public.",
      optional: true,
      options: constants.PRIVACY_OPTIONS,
    },
    printmarkUri: {
      type: "string",
      label: "Printmark URI",
      description: "Uri of an image to use in print orders of your photos, usually, a team, company logo, your signature.",
      optional: true,
    },
    watermarkUri: {
      type: "string",
      label: "Watermark URI",
      description: "Uri of an image to be applied on your photos as a watermark for protection.",
      optional: true,
    },
    themeUri: {
      type: "string",
      label: "Theme URI",
      description: "Only applies to legacy accounts.",
      optional: true,
    },
    templateUri: {
      type: "string",
      label: "Template URI",
      description: "Uri of template, preset settings to be applied on the album.",
      optional: true,
    },
    allowDownloads: {
      type: "boolean",
      label: "Allow Downloads",
      description: "Allow downloads of this album?",
      optional: true,
    },
    backprinting: {
      type: "string",
      label: "Backprinting",
      description: "Text to appear in the back of print orders of your photos.",
      optional: true,
    },
    boutiquePackaging: {
      type: "string",
      label: "Boutique Packaging",
      description: "Is this album available for Boutique Packaging in your customers orders?",
      optional: true,
      options: constants.BOUTIQUE_PACKAGING_OPTIONS,
    },
    canRank: {
      type: "boolean",
      label: "Can Rank",
      description: "Enable Canrank property of the album.",
      optional: true,
    },
    clean: {
      type: "boolean",
      label: "Clean",
      description: "Enable Clean property of the album.",
      optional: true,
    },
    comments: {
      type: "boolean",
      label: "Comments",
      description: "Allow other users leave comments in the album?",
      optional: true,
    },
    description: {
      type: "string",
      label: "Description",
      description: "The human-readable description",
      optional: true,
    },
    downloadPassword: {
      type: "string",
      label: "Download Password",
      description: "The password used for protecting album download.",
      optional: true,
    },
    EXIF: {
      type: "string",
      label: "EXIF",
      description: "Display a photo's EXIF information.",
      optional: true,
    },
    familyEdit: {
      type: "boolean",
      label: "Family Edit",
      description: "Enable FamilyEdit property of the album.",
      optional: true,
    },
    filenames: {
      type: "boolean",
      label: "Filenames",
      description: "Enable Filenames property of the album.",
      optional: true,
    },
    friendEdit: {
      type: "string",
      label: "Friend Edit",
      description: "Allow this album available for granting special privileges to friends and family with an Smugmug account?",
      optional: true,
    },
    geography: {
      type: "boolean",
      label: "Geography",
      description: "Enable Geography property of the album.",
      optional: true,
    },
    header: {
      type: "string",
      label: "Header",
      description: "Use a customer header for the album appearance?",
      optional: true,
      options: constants.HEADER_OPTIONS,
    },
    hideOwner: {
      type: "boolean",
      label: "Hide Owner",
      description: "Hide owner information from the album?",
      optional: true,
    },
    interceptShipping: {
      type: "string",
      label: "Intercept Shipping",
      description: "Personal Delivery.",
      optional: true,
    },
    keywords: {
      type: "string",
      label: "Keywords",
      description: "A semicolon-separated list of keywords.",
      optional: true,
    },
    largestSize: {
      type: "string",
      label: "Largest Size",
      description: "Largest display sizes for images in the album.",
      optional: true,
    },
    packagingBranding: {
      type: "boolean",
      label: "Packaging Branding",
      description: "Enable PackagingBranding property of the album.",
      optional: true,
    },
    password: {
      type: "string",
      label: "Password",
      description: "The password used for protecting album access.",
      optional: true,
    },
    passwordHint: {
      type: "string",
      label: "Password Hint",
      description: "The hint for the album-access password.",
      optional: true,
    },
    printable: {
      type: "string",
      label: "Printable",
      description: "Allow images of this album to be available for printing?",
      optional: true,
    },
    proofDays: {
      type: "string",
      label: "Proof Days",
      description: "A proof-delay between 1 and 7 business days for customer orders.",
      optional: true,
    },
    protected: {
      type: "boolean",
      label: "Protected",
      description: "Enable right-click protection?",
      optional: true,
    },
    share: {
      type: "boolean",
      label: "Share",
      description: "Allow this album to be shared?",
      optional: true,
    },
    slideshow: {
      type: "boolean",
      label: "Slideshow",
      description: "Enable the slideshow content block on this album?",
      optional: true,
    },
    sortDirection: {
      type: "string",
      label: "Sort Direction",
      description: "Specifies the direction in which to sort album images.",
      optional: true,
      options: constants.SORT_DIRECTION_OPTIONS,
    },
    sortMethod: {
      type: "string",
      label: "Sort Method",
      description: "Album's image property to use for sorting?",
      optional: true,
      options: constants.SORT_METHOD_OPTIONS,
    },
    squareThumbs: {
      type: "boolean",
      label: "Square Thumbs",
      description: "Enable thumbnails in album's images (only available in SmugMug style).",
      optional: true,
    },
    uploadKey: {
      type: "string",
      label: "Upload Key",
      description: "A key for your guests to upload images to the album.",
      optional: true,
    },
    watermark: {
      type: "boolean",
      label: "Watermark",
      description: "Automatically apply watermark to uploaded images?",
      optional: true,
    },
    worldSearchable: {
      type: "string",
      label: "World Searchable",
      description: "Allow this album to appear in external search results? Can be \"No\" or \"Inherit from User\".",
      optional: true,
      options: constants.SEARCHABLE_OPTIONS,
    },
    autoRename: {
      type: "boolean",
      label: "Auto Rename",
      description: "Auto-rename conflicting album NiceNames?",
      optional: true,
    },
    securityType: {
      type: "string",
      label: "SecurityType",
      description: "Access protection method for the folder.",
      optional: true,
    },
    highlightAlbumImageUri: {
      type: "string",
      label: "Highlight Album Image URI",
      description: "Uri of an image which can be used as a representative of the entire album.",
      optional: true,
    },
    albumTemplateUri: {
      type: "string",
      label: "Album Template URI",
      description: "Specify default album presets by providing an AlbumTemplateUri.",
      optional: true,
    },
    smugSearchable: {
      type: "string",
      label: "Smug Searchable",
      description: "Allow this album to appear in SmugMug search results? Can be \"No\" or \"Inherit from User\".",
      optional: true,
      options: constants.SEARCHABLE_OPTIONS,
    },
  },
  async run({ $ }) {
    const data = {
      NiceName: this.niceName,
      UrlName: this.urlName,
      Title: this.title,
      Privacy: this.privacy,
      PrintmarkUri: this.printmarkUri,
      WatermarkUri: this.watermarkUri,
      ThemeUri: this.themeUri,
      TemplateUri: this.templateUri,
      AllowDownloads: this.allowDownloads,
      Backprinting: this.backprinting,
      BoutiquePackaging: this.boutiquePackaging,
      CanRank: this.canRank,
      Clean: this.clean,
      Comments: this.comments,
      Description: this.description,
      DownloadPassword: this.downloadPassword,
      EXIF: this.EXIF,
      FamilyEdit: this.familyEdit,
      Filenames: this.filenames,
      FriendEdit: this.friendEdit,
      Geography: this.geography,
      Header: this.header,
      HideOwner: this.hideOwner,
      InterceptShipping: this.interceptShipping,
      Keywords: this.keywords,
      LargestSize: this.largestSize,
      PackagingBranding: this.packagingBranding,
      Password: this.password,
      PasswordHint: this.passwordHint,
      Printable: this.printable,
      ProofDays: this.proofDays,
      Protected: this.protected,
      Share: this.share,
      Slideshow: this.slideshow,
      SortDirection: this.sortDirection,
      SortMethod: this.sortMethod,
      SquareThumbs: this.squareThumbs,
      UploadKey: this.uploadKey,
      Watermark: this.watermark,
      WorldSearchable: this.worldSearchable,
      AutoRename: this.AatoRename,
      SecurityType: this.securityType,
      HighlightAlbumImageUri: this.highlightAlbumImageUri,
      AlbumTemplateUri: this.albumTemplateUri,
      SmugSearchable: this.smugSearchable,
    };
    const nickname = await this.smugmug.getAuthenticatedUserNickname();
    const response = await this.smugmug.createAlbum(nickname, this.folder, {
      $,
      data,
    });
    if (response) {
      $.export("$summary", `Created album with key ${response.Response.Album.AlbumKey}`);
    }
    return response;
  },
};