//
// Copyright 2019 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//

#import <SignalServiceKit/BaseModel.h>
#import <SignalServiceKit/StickerInfo.h>

NS_ASSUME_NONNULL_BEGIN

@class SDSAnyWriteTransaction;
@class StickerPack;

@interface StickerPackItem : MTLModel

@property (nonatomic, readonly) UInt32 stickerId;
@property (nonatomic, readonly) NSString *emojiString;
@property (nonatomic, readonly, nullable) NSString *contentType;

- (instancetype)initWithStickerId:(UInt32)stickerId
                      emojiString:(NSString *)emojiString
                      contentType:(nullable NSString *)contentType;

- (StickerInfo *)stickerInfoWithStickerPack:(StickerPack *)stickerPack;

@end

#pragma mark -

@interface StickerPack : BaseModel

@property (nonatomic, readonly) StickerPackInfo *info;

@property (nonatomic, readonly, nullable) NSString *title;
@property (nonatomic, readonly, nullable) NSString *author;
@property (nonatomic, readonly) StickerPackItem *cover;
@property (nonatomic, readonly) NSArray<StickerPackItem *> *items;

// Convenience accessors.
@property (nonatomic, readonly) NSData *packId;
@property (nonatomic, readonly) NSData *packKey;
@property (nonatomic, readonly) StickerInfo *coverInfo;
@property (nonatomic, readonly) NSArray<StickerInfo *> *stickerInfos;

@property (nonatomic, readonly) NSDate *dateCreated;
@property (nonatomic, readonly) BOOL isInstalled;

+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithUniqueId:(NSString *)uniqueId NS_UNAVAILABLE;
- (instancetype)initWithGrdbId:(int64_t)grdbId uniqueId:(NSString *)uniqueId NS_UNAVAILABLE;

- (instancetype)initWithInfo:(StickerPackInfo *)info
                       title:(nullable NSString *)title
                      author:(nullable NSString *)author
                       cover:(StickerPackItem *)cover
                    stickers:(NSArray<StickerPackItem *> *)items NS_DESIGNATED_INITIALIZER;

// --- CODE GENERATION MARKER

// This snippet is generated by /Scripts/sds_codegen/sds_generate.py. Do not manually edit it, instead run
// `sds_codegen.sh`.

// clang-format off

- (instancetype)initWithGrdbId:(int64_t)grdbId
                      uniqueId:(NSString *)uniqueId
                          author:(nullable NSString *)author
                           cover:(StickerPackItem *)cover
                     dateCreated:(NSDate *)dateCreated
                            info:(StickerPackInfo *)info
                     isInstalled:(BOOL)isInstalled
                           items:(NSArray<StickerPackItem *> *)items
                           title:(nullable NSString *)title
NS_DESIGNATED_INITIALIZER NS_SWIFT_NAME(init(grdbId:uniqueId:author:cover:dateCreated:info:isInstalled:items:title:));

// clang-format on

// --- CODE GENERATION MARKER

+ (NSString *)uniqueIdForStickerPackInfo:(StickerPackInfo *)info;

- (void)updateWithIsInstalled:(BOOL)isInstalled transaction:(SDSAnyWriteTransaction *)transaction;

@end

NS_ASSUME_NONNULL_END
