// Path: components/email/src/main/java/com/example/email/SendEmail.java
// public class SendEmail {
//     private final String queueName;
//     private final RabbitTemplate rabbitTemplate;
// 
//     public SendEmail(String queueName, RabbitTemplate rabbitTemplate) {
//         this.queueName = queueName;
//         this.rabbitTemplate = rabbitTemplate;
//     }
// 
//     public void run(EmailMessage message) {
//         rabbitTemplate.convertAndSend(queueName, message);
//     }
// }
// 
// Path: components/subscriptions/src/main/java/com/example/subscriptions/CreateSubscription.java
// public class CreateSubscription {
// 
//     private final Service billingService;
//     private final SendEmail emailSender;
//     private final SubscriptionRepository subscriptions;
// 
//     public CreateSubscription(
//             Service billingService,
//             SendEmail emailSender, SubscriptionRepository subscriptions) {
//         this.billingService = billingService;
//         this.emailSender = emailSender;
//         this.subscriptions = subscriptions;
//     }
// 
//     public void run(String userId, String packageId) {
//         subscriptions.create(new Subscription(userId, packageId));
//         billingService.billUser(new BillingRequest(userId, 100));
//         emailSender.run(new EmailMessage("me@example.com", "Subscription Created", "Some email body"));
//     }
// }
// 
// Path: components/subscriptions/src/main/java/com/example/subscriptions/Subscription.java
// @Entity
// public class Subscription {
// 
//     @Id
//     @GeneratedValue
//     private Long id;
// 
//     private String userId;
// 
//     private String packageId;
// 
//     protected Subscription() {}
// 
//     public Subscription(String userId, String packageId) {
//         this.userId = userId;
//         this.packageId = packageId;
//     }
// 
//     public String getUserId() {
//         return userId;
//     }
// 
//     public void setUserId(String userId) {
//         this.userId = userId;
//     }
// 
//     public String getPackageId() {
//         return packageId;
//     }
// 
//     public void setPackageId(String packageId) {
//         this.packageId = packageId;
//     }
// }
// 
// Path: components/subscriptions/src/main/java/com/example/subscriptions/SubscriptionRepository.java
// public class SubscriptionRepository {
//     private NamedParameterJdbcTemplate datasource;
// 
//     public SubscriptionRepository(NamedParameterJdbcTemplate datasource){
// 
//         this.datasource = datasource;
//     }
// 
//     public List<Subscription> all() {
//         return datasource.query("SELECT * FROM subscriptions;", (record, rowNumber) -> {
//             return new Subscription(record.getString("userId"), record.getString("packageId"));
//         });
//     }
// 
//     public void create(Subscription subscription) {
//         HashMap<String, Object> values = new HashMap<>();
//         values.put("userId", subscription.getUserId());
//         values.put("packageId", subscription.getPackageId());
// 
//         datasource.update("INSERT INTO subscriptions (userId, packageId) VALUES (:userId, :packageId);", values);
//     }
// }


import com.example.billing.Service;
import com.example.email.SendEmail;
import com.example.subscriptions.CreateSubscription;
import com.example.subscriptions.Subscription;
import com.example.subscriptions.SubscriptionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.CounterService;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
package com.example.ums.subscriptions;




@RestController
@RequestMapping("/subscriptions")
public class SubscriptionsController {

    @Autowired
    SubscriptionRepository subscriptions;

    @Autowired
    Service billingService;

    @Autowired
    SendEmail emailSender;

    @Autowired
    private CounterService counter;

    @RequestMapping(method = RequestMethod.GET)
    public Iterable<Subscription> index() {
        return subscriptions.all();
    }

    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity<String> create(@RequestBody Map<String, String> params) {
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.add("content-type", MediaType.APPLICATION_JSON.toString());

// Path: components/email/src/main/java/com/example/email/SendEmail.java
// public class SendEmail {
//     private final String queueName;
//     private final RabbitTemplate rabbitTemplate;
// 
//     public SendEmail(String queueName, RabbitTemplate rabbitTemplate) {
//         this.queueName = queueName;
//         this.rabbitTemplate = rabbitTemplate;
//     }
// 
//     public void run(EmailMessage message) {
//         rabbitTemplate.convertAndSend(queueName, message);
//     }
// }
// 
// Path: components/subscriptions/src/main/java/com/example/subscriptions/CreateSubscription.java
// public class CreateSubscription {
// 
//     private final Service billingService;
//     private final SendEmail emailSender;
//     private final SubscriptionRepository subscriptions;
// 
//     public CreateSubscription(
//             Service billingService,
//             SendEmail emailSender, SubscriptionRepository subscriptions) {
//         this.billingService = billingService;
//         this.emailSender = emailSender;
//         this.subscriptions = subscriptions;
//     }
// 
//     public void run(String userId, String packageId) {
//         subscriptions.create(new Subscription(userId, packageId));
//         billingService.billUser(new BillingRequest(userId, 100));
//         emailSender.run(new EmailMessage("me@example.com", "Subscription Created", "Some email body"));
//     }
// }
// 
// Path: components/subscriptions/src/main/java/com/example/subscriptions/Subscription.java
// @Entity
// public class Subscription {
// 
//     @Id
//     @GeneratedValue
//     private Long id;
// 
//     private String userId;
// 
//     private String packageId;
// 
//     protected Subscription() {}
// 
//     public Subscription(String userId, String packageId) {
//         this.userId = userId;
//         this.packageId = packageId;
//     }
// 
//     public String getUserId() {
//         return userId;
//     }
// 
//     public void setUserId(String userId) {
//         this.userId = userId;
//     }
// 
//     public String getPackageId() {
//         return packageId;
//     }
// 
//     public void setPackageId(String packageId) {
//         this.packageId = packageId;
//     }
// }
// 
// Path: components/subscriptions/src/main/java/com/example/subscriptions/SubscriptionRepository.java
// public class SubscriptionRepository {
//     private NamedParameterJdbcTemplate datasource;
// 
//     public SubscriptionRepository(NamedParameterJdbcTemplate datasource){
// 
//         this.datasource = datasource;
//     }
// 
//     public List<Subscription> all() {
//         return datasource.query("SELECT * FROM subscriptions;", (record, rowNumber) -> {
//             return new Subscription(record.getString("userId"), record.getString("packageId"));
//         });
//     }
// 
//     public void create(Subscription subscription) {
//         HashMap<String, Object> values = new HashMap<>();
//         values.put("userId", subscription.getUserId());
//         values.put("packageId", subscription.getPackageId());
// 
//         datasource.update("INSERT INTO subscriptions (userId, packageId) VALUES (:userId, :packageId);", values);
//     }
// }


// Path: applications/ums/src/main/java/com/example/ums/subscriptions/SubscriptionsController.java
import com.example.billing.Service;
import com.example.email.SendEmail;
import com.example.subscriptions.CreateSubscription;
import com.example.subscriptions.Subscription;
import com.example.subscriptions.SubscriptionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.CounterService;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;

package com.example.ums.subscriptions;




@RestController
@RequestMapping("/subscriptions")
public class SubscriptionsController {

    @Autowired
    SubscriptionRepository subscriptions;

    @Autowired
    Service billingService;

    @Autowired
    SendEmail emailSender;

    @Autowired
    private CounterService counter;

    @RequestMapping(method = RequestMethod.GET)
    public Iterable<Subscription> index() {
        return subscriptions.all();
    }

    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity<String> create(@RequestBody Map<String, String> params) {
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.add("content-type", MediaType.APPLICATION_JSON.toString());

        new CreateSubscription(billingService, emailSender, subscriptions)