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

#import "TSPrivateStoryThread.h"
#import <SignalServiceKit/SignalServiceKit-Swift.h>

@implementation TSPrivateStoryThread

- (instancetype)initWithUniqueId:(NSString *)uniqueId
                            name:(NSString *)name
                   allowsReplies:(BOOL)allowsReplies
                       addresses:(NSArray<SignalServiceAddress *> *)addresses
                        viewMode:(TSThreadStoryViewMode)viewMode
{
    self = [super initWithUniqueId:uniqueId];
    if (self) {
        self.name = name;
        self.allowsReplies = allowsReplies;
        self.addresses = addresses;
        self.storyViewMode = viewMode;
    }
    return self;
}

- (instancetype)initWithName:(NSString *)name
               allowsReplies:(BOOL)allowsReplies
                   addresses:(NSArray<SignalServiceAddress *> *)addresses
                    viewMode:(TSThreadStoryViewMode)viewMode
{
    NSString *uniqueId = [[self class] generateUniqueId];
    self = [super initWithUniqueId:uniqueId];
    if (self) {
        self.name = name;
        self.allowsReplies = allowsReplies;
        self.addresses = addresses;
        self.storyViewMode = viewMode;
    }
    return self;
}

// --- 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
   conversationColorNameObsolete:(NSString *)conversationColorNameObsolete
                    creationDate:(nullable NSDate *)creationDate
             editTargetTimestamp:(nullable NSNumber *)editTargetTimestamp
              isArchivedObsolete:(BOOL)isArchivedObsolete
          isMarkedUnreadObsolete:(BOOL)isMarkedUnreadObsolete
            lastInteractionRowId:(uint64_t)lastInteractionRowId
          lastSentStoryTimestamp:(nullable NSNumber *)lastSentStoryTimestamp
       lastVisibleSortIdObsolete:(uint64_t)lastVisibleSortIdObsolete
lastVisibleSortIdOnScreenPercentageObsolete:(double)lastVisibleSortIdOnScreenPercentageObsolete
         mentionNotificationMode:(TSThreadMentionNotificationMode)mentionNotificationMode
                    messageDraft:(nullable NSString *)messageDraft
          messageDraftBodyRanges:(nullable MessageBodyRanges *)messageDraftBodyRanges
          mutedUntilDateObsolete:(nullable NSDate *)mutedUntilDateObsolete
     mutedUntilTimestampObsolete:(uint64_t)mutedUntilTimestampObsolete
           shouldThreadBeVisible:(BOOL)shouldThreadBeVisible
                   storyViewMode:(TSThreadStoryViewMode)storyViewMode
                       addresses:(NSArray<SignalServiceAddress *> *)addresses
                   allowsReplies:(BOOL)allowsReplies
                            name:(NSString *)name
{
    self = [super initWithGrdbId:grdbId
                        uniqueId:uniqueId
     conversationColorNameObsolete:conversationColorNameObsolete
                      creationDate:creationDate
               editTargetTimestamp:editTargetTimestamp
                isArchivedObsolete:isArchivedObsolete
            isMarkedUnreadObsolete:isMarkedUnreadObsolete
              lastInteractionRowId:lastInteractionRowId
            lastSentStoryTimestamp:lastSentStoryTimestamp
         lastVisibleSortIdObsolete:lastVisibleSortIdObsolete
lastVisibleSortIdOnScreenPercentageObsolete:lastVisibleSortIdOnScreenPercentageObsolete
           mentionNotificationMode:mentionNotificationMode
                      messageDraft:messageDraft
            messageDraftBodyRanges:messageDraftBodyRanges
            mutedUntilDateObsolete:mutedUntilDateObsolete
       mutedUntilTimestampObsolete:mutedUntilTimestampObsolete
             shouldThreadBeVisible:shouldThreadBeVisible
                     storyViewMode:storyViewMode];

    if (!self) {
        return self;
    }

    _addresses = addresses;
    _allowsReplies = allowsReplies;
    _name = name;

    return self;
}

// clang-format on

// --- CODE GENERATION MARKER

- (BOOL)isMyStory
{
    return [self.uniqueId isEqualToString:[self class].myStoryUniqueId];
}

- (NSString *)name
{
    if (self.isMyStory) {
        return OWSLocalizedString(
            @"MY_STORY_NAME", @"Name for the 'My Story' default story that sends to all the user's contacts.");
    }

    return _name;
}

@end
