//
//  RCTRnUpdateResultParams.m
//  LocalApp
//
//  Created by xiaoyu on 2026/1/4.
//

#import "RCTRnUpdateResultParams.h"

@implementation RCTRnUpdateResultParams: NSObject


- (instancetype)initWithCode:(NSInteger)code msg:(NSString *)msg
{
  self = [super init];
  if(self) {
    _code = code;
    _msg = msg;
  }
  return self;
}

- (NSDictionary *)toDictionary
{
  return @{
    @"code": @(_code),
    @"msg": _msg ?: @""
  };
}

- (NSDictionary *)toDictionaryWithMsg:(NSString *)msg
{
  NSMutableDictionary *dict = [[self toDictionary] mutableCopy];
  dict[@"msg"] = msg ?: dict[@"msg"];
  return [dict copy];
}


// 静态实现

+ (instancetype) success {
  static RCTRnUpdateResultParams *params;
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    params = [[RCTRnUpdateResultParams alloc] initWithCode:200 msg:@"OK"];
  });
  return params;
}


+ (instancetype)ppkVersionInstall {
    static RCTRnUpdateResultParams *obj;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        obj = [[RCTRnUpdateResultParams alloc] initWithCode:201 msg:@"版本已安装"];
    });
    return obj;
}

+ (instancetype)ppkVersionUninstall {
    static RCTRnUpdateResultParams *obj;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        obj = [[RCTRnUpdateResultParams alloc] initWithCode:202 msg:@"版本已下载，未安装"];
    });
    return obj;
}

+ (instancetype)ppkVersionUndownload {
    static RCTRnUpdateResultParams *obj;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        obj = [[RCTRnUpdateResultParams alloc] initWithCode:203 msg:@"版本未下载"];
    });
    return obj;
}

+ (instancetype)errorNotExist {
    static RCTRnUpdateResultParams *obj;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        obj = [[RCTRnUpdateResultParams alloc] initWithCode:404 msg:@"不存在的请求"];
    });
    return obj;
}

+ (instancetype)errorParams {
    static RCTRnUpdateResultParams *obj;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        obj = [[RCTRnUpdateResultParams alloc] initWithCode:501 msg:@"参数错误"];
    });
    return obj;
}

+ (instancetype)errorRuntime {
    static RCTRnUpdateResultParams *obj;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        obj = [[RCTRnUpdateResultParams alloc] initWithCode:500 msg:@"运行时错误"];
    });
    return obj;
}

+ (NSDictionary *)builder:(NSString *)code msg:(NSString *)msg
{
  return @{
    @"code": code,
    @"msg": msg ?: @""
  };
}


@end
