Change mapping

This commit is contained in:
problematicconsumer
2024-02-17 11:58:34 +03:30
parent 0aeb0e346f
commit 3541f8e3db
9 changed files with 269 additions and 364 deletions

View File

@@ -1,37 +1,35 @@
import 'package:dart_mappable/dart_mappable.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'singbox_rule.mapper.dart';
part 'singbox_rule.freezed.dart';
part 'singbox_rule.g.dart';
@MappableClass()
class SingboxRule with SingboxRuleMappable {
const SingboxRule({
this.domains,
this.ip,
this.port,
this.protocol,
this.network = RuleNetwork.tcpAndUdp,
this.outbound = RuleOutbound.proxy,
});
@freezed
class SingboxRule with _$SingboxRule {
const SingboxRule._();
final String? domains;
final String? ip;
final String? port;
final String? protocol;
final RuleNetwork network;
final RuleOutbound outbound;
@JsonSerializable(fieldRename: FieldRename.kebab)
const factory SingboxRule({
String? domains,
String? ip,
String? port,
String? protocol,
@Default(RuleNetwork.tcpAndUdp) RuleNetwork network,
@Default(RuleOutbound.proxy) RuleOutbound outbound,
}) = _SingboxRule;
factory SingboxRule.fromJson(Map<String, dynamic> json) =>
_$SingboxRuleFromJson(json);
}
@MappableEnum()
enum RuleOutbound { proxy, bypass, block }
@MappableEnum()
@JsonEnum(valueField: 'key')
enum RuleNetwork {
@MappableValue("")
tcpAndUdp,
tcpAndUdp(""),
tcp("tcp"),
udp("udp");
@MappableValue("tcp")
tcp,
const RuleNetwork(this.key);
@MappableValue("udp")
udp;
final String? key;
}