96 lines
2.5 KiB
Dart
96 lines
2.5 KiB
Dart
import 'package:please_pay_me/data/models/json.dart';
|
|
|
|
enum WeekendPolicy {
|
|
beforeWeekend('before_weekend', 'До выходных'),
|
|
afterWeekend('after_weekend', 'После выходных');
|
|
|
|
const WeekendPolicy(this.wire, this.label);
|
|
|
|
factory WeekendPolicy.fromWire(Object? value) {
|
|
return WeekendPolicy.values.firstWhere(
|
|
(policy) => policy.wire == asString(value),
|
|
orElse: () => WeekendPolicy.beforeWeekend,
|
|
);
|
|
}
|
|
|
|
final String wire;
|
|
final String label;
|
|
}
|
|
|
|
class UpcomingPay {
|
|
const UpcomingPay({
|
|
required this.date,
|
|
required this.scheduledDay,
|
|
required this.percent,
|
|
required this.amount,
|
|
});
|
|
|
|
factory UpcomingPay.fromJson(Map<String, dynamic> json) {
|
|
return UpcomingPay(
|
|
date: asDate(json['date']),
|
|
scheduledDay: asInt(json['scheduled_day']),
|
|
percent: asDouble(json['percent']),
|
|
amount: asDouble(json['amount']),
|
|
);
|
|
}
|
|
|
|
final DateTime date;
|
|
final int scheduledDay;
|
|
final double percent;
|
|
final double amount;
|
|
}
|
|
|
|
class Job {
|
|
const Job({
|
|
required this.id,
|
|
required this.userId,
|
|
required this.name,
|
|
required this.salaryAmount,
|
|
required this.currency,
|
|
required this.payDays,
|
|
required this.firstPayPercent,
|
|
required this.weekendPolicy,
|
|
required this.isActive,
|
|
required this.nextPays,
|
|
});
|
|
|
|
factory Job.fromJson(Map<String, dynamic> json) {
|
|
final rawDays = json['pay_days'];
|
|
return Job(
|
|
id: asInt(json['id']),
|
|
userId: asInt(json['user_id']),
|
|
name: asString(json['name']),
|
|
salaryAmount: asDouble(json['salary_amount']),
|
|
currency: asString(json['currency'], fallback: 'RUB'),
|
|
payDays: rawDays is List ? rawDays.map(asInt).toList() : const [],
|
|
firstPayPercent: asDouble(json['first_pay_percent']),
|
|
weekendPolicy: WeekendPolicy.fromWire(json['weekend_policy']),
|
|
isActive: asBool(json['is_active']),
|
|
nextPays: asList(json['next_pays']).map(UpcomingPay.fromJson).toList(),
|
|
);
|
|
}
|
|
|
|
final int id;
|
|
final int userId;
|
|
final String name;
|
|
final double salaryAmount;
|
|
final String currency;
|
|
final List<int> payDays;
|
|
final double firstPayPercent;
|
|
final WeekendPolicy weekendPolicy;
|
|
final bool isActive;
|
|
final List<UpcomingPay> nextPays;
|
|
|
|
UpcomingPay? get nextPay => nextPays.isEmpty ? null : nextPays.first;
|
|
}
|
|
|
|
class JobsList {
|
|
const JobsList({required this.items});
|
|
|
|
factory JobsList.fromJson(Map<String, dynamic> json) {
|
|
return JobsList(items: asList(json['items']).map(Job.fromJson).toList());
|
|
}
|
|
|
|
final List<Job> items;
|
|
}
|