//
//  NvTimelineDataModel.m
//  SDKDemo
//
//  Created by shizhouhu on 2018/6/26.
 //
//

#import "NvTimelineDataModel.h"
#import "NvUtils.h"

@implementation NvEditDataModel

- (instancetype)init {
    self = [super init];
    self.isBlur = NO;
    self.speed = 1.f;
    self.volume = 1.f;
    self.uuid = [NvUtils uuidString];
    self.rotation = 0;
    self.brightness = 1;
    self.saturation = 1;
    self.contrast = 1;
    self.scaleX = 1;
    self.scaleY = 1;
    self.pan = 0;
    self.scan = 0;
    self.motionMode = NvsStreamingEngineImageClipMotionMode_ROI;
    self.hasMotion = YES;
    self.isArea = YES;
    self.isDefault = NO;
    return self;
}

- (id)copyWithZone:(NSZone *)zone {
    NvEditDataModel *new = NvEditDataModel.new;
    new.videoPath = self.videoPath;
    new.isBlur = self.isBlur;
    new.speed = self.speed;
    new.trimIn = self.trimIn;
    new.trimOut = self.trimOut;
    new.duration = self.duration;
    new.volume = self.volume;
    new.mute = self.mute;
    new.isImage = self.isImage;
    new.localIdentifier = self.localIdentifier;
    new.uuid = [NvUtils uuidString];
    new.brightness = self.brightness;
    new.contrast = self.contrast;
    new.saturation = self.saturation;
    new.rotation = self.rotation;
    new.scaleX = self.scaleX;
    new.scaleY = self.scaleY;
    new.motionMode = self.motionMode;
    new.startRect = self.startRect;
    new.endRect = self.endRect;
    new.hasMotion = self.hasMotion;
    
    return new;
}

@end

@implementation NvCaptionInfoModel
- (instancetype)init {
    self = [super init];
    self.scale = 1.f;
    self.translation = CGPointMake(0, 0);
    self.rotation = 0;
    self.anchorPoint = CGPointMake(0, 0);
    self.fontSize = 10;
//    self.color = [UIColor whiteColor];
    self.isDrawOutline = NO;
    self.uuid = [NvUtils uuidString];
    return self;
}

- (NSMutableArray *) changeUIColorToRGB:(UIColor *)color
{
    NSMutableArray *RGBStrValueArr = [[NSMutableArray alloc] init];
    NSString *RGBStr = nil;
    //获得RGB值描述
    NSString *RGBValue = [NSString stringWithFormat:@"%@",color];
    //将RGB值描述分隔成字符串
    NSArray *RGBArr = [RGBValue componentsSeparatedByString:@" "];
    //获取红色值
    int r = [[RGBArr objectAtIndex:1] intValue] * 255;
    RGBStr = [NSString stringWithFormat:@"%d",r];
    [RGBStrValueArr addObject:RGBStr];
    //获取绿色值
    int g = [[RGBArr objectAtIndex:2] intValue] * 255;
    RGBStr = [NSString stringWithFormat:@"%d",g];
    [RGBStrValueArr addObject:RGBStr];
    //获取蓝色值
    int b = [[RGBArr objectAtIndex:3] intValue] * 255;
    RGBStr = [NSString stringWithFormat:@"%d",b];
    [RGBStrValueArr addObject:RGBStr];
    
    int a = [[RGBArr objectAtIndex:4] intValue] * 255;
    RGBStr = [NSString stringWithFormat:@"%d",a];
    [RGBStrValueArr addObject:RGBStr];
    //返回保存RGB值的数组
    return RGBStrValueArr;
}

- (id)copyWithZone:(nullable NSZone *)zone {
    NvCaptionInfoModel *model = [NvCaptionInfoModel new];
    model.text = [[NSString alloc] initWithString:self.text];
    if (self.color) {
        NSMutableArray *colors = [self changeUIColorToRGB:self.color];
        if (colors.count == 4) {
            model.color = [UIColor colorWithRed:[colors[0] intValue]/255.0 green:[colors[1] intValue]/255.0 blue:[colors[2] intValue]/255.0 alpha:[colors[3] intValue]/255.0];
        } else {
            NSLog(@"color 解析错误");
            model.color = nil;
        }
    } else {
        model.color = nil;
    }
    model.anchorPoint = self.anchorPoint;
    model.rotation = self.rotation;
    model.scale = self.scale;
    model.fontSize = self.fontSize;
    model.translation = self.translation;
    model.uuid = [NvUtils uuidString];
    model.category = self.category;
    if (!self.styleId) {
        model.styleId = nil;
    } else {
        model.styleId = [[NSString alloc] initWithString:self.styleId];
    }
    model.inPoint = self.inPoint;
    model.outPoint = self.outPoint;
    model.isDrawOutline = self.isDrawOutline;
    if (self.outlineColor) {
        NSMutableArray *outlinecolors = [self changeUIColorToRGB:self.outlineColor];
        if (outlinecolors.count == 4) {
            model.outlineColor = [UIColor colorWithRed:[outlinecolors[0] intValue]/255.0 green:[outlinecolors[1] intValue]/255.0 blue:[outlinecolors[2] intValue]/255.0 alpha:[outlinecolors[3] intValue]/255.0];
        } else {
            NSLog(@"outlineColor 解析错误");
            model.outlineColor = nil;
        }
    } else {
        model.outlineColor = nil;
    }
    model.outlineWidth = self.outlineWidth;
    if (!self.fontFilePath) {
        model.fontFilePath = nil;
    } else {
        model.fontFilePath = [[NSString alloc] initWithString:self.fontFilePath];
    }
    model.alignment = self.alignment;
    model.isBold = self.isBold;
    model.isItalic = self.isItalic;
    model.isDrawShadow = self.isDrawShadow;
    return model;
}

@end

@implementation NvStickerInfoModel

- (instancetype)init {
    self = [super init];
    self.scale = 1.f;
    self.rotation = 0;
    self.volume = 1;
    self.translation = CGPointMake(0, 0);
    self.anchor = CGPointMake(0, 0);
    self.uuid = [NvUtils uuidString];
    self.isSlient = YES;
    return self;
}

- (id)copyWithZone:(NSZone *)zone {
    NvStickerInfoModel *new = NvStickerInfoModel.new;
    new.scale = self.scale;
    new.rotation = self.rotation;
    new.uuid = [NvUtils uuidString];
    new.translation = self.translation;
    new.anchor = self.anchor;
    new.packageId = self.packageId;
    new.inPoint = self.inPoint;
    new.outPoint = self.outPoint;
    new.isCustomSticer = self.isCustomSticer;
    new.customImagePath = self.customImagePath;
    new.isSlient = self.isSlient;
    new.volume = self.volume;
    
    return new;
}

@end

@implementation NvParticleInfoModel
- (instancetype)init {
    self = [super init];
    self.particleRateValue = 1.f;
    self.particleSizeValue = 1.f;
    self.particleLocation = [[NSMutableArray alloc] init];
    self.emitterName = [[NSMutableArray alloc] init];
    self.uuid = [NvUtils uuidString];
    return self;
}
@end

@implementation NvTimeFilterInfoModel
- (instancetype)init {
    self = [super init];
    self.addInReverseMode = NO;
    self.isDouyin = NO;
    self.uuid = [NvUtils uuidString];
    self.strength = 1;
    return self;
}

- (id)copyWithZone:(NSZone *)zone {
    NvTimeFilterInfoModel *new = NvTimeFilterInfoModel.new;
    new.addInReverseMode = self.addInReverseMode;
    new.isDouyin = self.isDouyin;
    new.uuid = [NvUtils uuidString];
    new.inPoint = self.inPoint;
    new.outPoint = self.outPoint;
    new.name = [NSString stringWithFormat:@"%@",self.name];
    new.strength = self.strength;
    
    return new;
}
@end

@implementation NvWatermarkInfoModel
- (instancetype)init {
    self = [super init];
    self.opacity = 1;
    self.position = 0;
    return self;
}
@end

@implementation NvTransitionInfoModel
- (instancetype)init {
    self = [super init];
    self.uuid = [NvUtils uuidString];
    self.builtinName = @"Fade";
    return self;
}
@end

@implementation NvDubbingInfoModel
- (instancetype)init {
    self = [super init];
    self.volume = 1;
    return self;
}

- (id)copyWithZone:(nullable NSZone *)zone {
    NvDubbingInfoModel *model = [NvDubbingInfoModel new];
    model.dubbingFilePath = [[NSString alloc] initWithString:self.dubbingFilePath];
    model.inPoint = self.inPoint;
    model.trimIn = self.trimIn;
    model.duration = self.duration;
    model.speed = self.speed;
    model.volume = self.volume;
    model.builtInFxName = self.builtInFxName;
    return model;
}

@end

@implementation NvDubbingModel

- (instancetype)init {
    self = [super init];
    self.volume = 1;
    return self;
}

- (id)copyWithZone:(nullable NSZone *)zone {
    NvDubbingModel *model = [NvDubbingModel new];
    model.volume = self.volume;
    model.dubbingInfoModels = [[NSMutableArray alloc] initWithArray:self.dubbingInfoModels copyItems:YES];
    return model;
}

@end

@implementation NvMusicInfoModel

- (instancetype)init {
    self = [super init];
    self.isBGM = false;
    self.inPoint = 0;
    self.isFade = NO;
    return self;
}

- (id)copyWithZone:(NSZone *)zone {
    NvMusicInfoModel *new = NvMusicInfoModel.new;
    new.musicPath = [NSString stringWithFormat:@"%@",self.musicPath];
    new.trimIn = self.trimIn;
    new.trimOut = self.trimOut;
    new.duration = self.duration;
    new.volume = self.volume;
    new.musicName = [NSString stringWithFormat:@"%@",self.musicName];
    new.musicAuthorName = [NSString stringWithFormat:@"%@",self.musicAuthorName];
    new.musicCoverImage = [UIImage imageWithCGImage:self.musicCoverImage.CGImage];
    new.isBGM = self.isBGM;
    new.isFade = self.isFade;
    return new;
}

@end

@implementation NvThemeInfoModel
- (instancetype)init {
    self = [super init];
    self.volume = 1;
    return self;
}

- (id)copyWithZone:(NSZone *)zone {
    NvThemeInfoModel *new = NvThemeInfoModel.new;
    new.volume = self.volume;
    new.themeName = [NSString stringWithFormat:@"%@",self.themeName];
    new.themeString = [NSString stringWithFormat:@"%@",self.themeString];
    new.thenmeRoleInTheme = self.thenmeRoleInTheme;
    return new;
}
@end
